$compact optimize(3) debug pw(79) rom /*********************************************************************** ** ** ** ** ** OBJECTIVES: ** ** ** ** 1. To demonstrate the concepts behind synchronous vs. ** ** asynchronous MULTIBUS-II system calls. ** ** ** ** 2. To better acquaint the user with the idea of sending ** ** and receiving solicited messages using the iRMX II/III ** ** Operating Systems. ** ** ** ** 3. To demonstrate buffer pool usage. ** ** ** ** ** ** USAGE: ** ** ** ** This program can be executed on any MULTIBUS-II board ** ** running the iRMX II/III Operating System. ** ** The board must be situated in slot CLIENT$PSB$SLOT, where ** ** CLIENT$PSB$SLOT and SERVER$PSB$SLOT are defined in utils.lit. ** ** ** ** ** ** ALGORITHM: ** ** ** ** 1. Enable in-line exception handling feature. ** ** ** ** 2. Create a port object and associate it with a default ** ** remote socket. ** ** ** ** 3. Create a buffer pool object and associate it with the ** ** port created in step 2. ** ** ** ** 4. Create a number of buffers and release buffers to the ** ** buffer pool above. ** ** ** ** 5. Prompt the user for a string of characters (the message). ** ** ** ** 6. Encrypt the message. ** ** ** ** 7. Send the encrypted message to the board in slot ** ** SERVER$PSB$SLOT. (The message is sent asynchronously) ** ** ** ** 8. Wait to receive the decrypted message back from board in ** ** slot SERVER$PSB$SLOT. ** ** (Here, we must ensure that the transaction ID of the ** ** message sent is equal to the transaction ID of the ** ** received message.) ** ** ** ** 9. Display the message received to the console. ** ** ** ** 10.Release the buffer used by the Nucleus (the buffer used ** ** by the iRMX II/III Nucleus during message passing) back ** ** to the buffer pool. ** ** ** ** 11. Repeat steps 5 - 11. ** ** ** ** ** ***********************************************************************/ client: DO; $INCLUDE (utils.lit) $INCLUDE (utils.ext) $INCLUDE (:RMX:inc/nuclus.ext) $INCLUDE (:RMX:inc/bios.ext) $INCLUDE (:RMX:inc/eios.ext) $INCLUDE (:RMX:inc/hi.ext) $INCLUDE (:RMX:inc/udi.ext) DECLARE bufpool$tkn TOKEN, buffer$tkn TOKEN, eh_handler EX_HANDLER_STRUCT, in$buff$ptr POINTER, msg$info$struc MSG_INFO_STRUCT, port$info$struc PORT_INFO_STRUCT, port$tkn TOKEN, segment$tkn TOKEN, server$socket DWORD, server$socket$ovl STRUCTURE (psb$slot WORD, port$id WORD) AT (@server$socket), socket DWORD, status WORD, trans$id WORD, control$msg (20) BYTE, count BYTE, index BYTE, not$ok BYTE, response$p (255) BYTE, response$p2 (255) BYTE; DECLARE message (*) BYTE DATA (32,'Enter any string of characters: '), message2 (*) BYTE DATA (21,'Message received is: '), message3 (*) BYTE DATA (2,CR,LF,0); /************************************************************************ ************************* MAIN PROGRAN BEGINS ************************** ************************************************************************/ main: /* Enable in-line exception handling */ CALL rq$get$exception$handler(@eh_handler,@status); eh_handler.mode = 0; CALL rq$set$exception$handler(@eh_handler,@status); /* Create the port object for this board */ port$info$struc.portid = CLIENT$PORT$ID; /* This Board */ port$info$struc.type = DATA$SERVICE; /* Transport Protocol */ port$info$struc.flags = FIFO$PORT$QUEUEING; port$info$struc.reserved = 0; port$tkn = rqcreate$port (2, @port$info$struc,@status); CALL check$exception (@(14,'rq$create$port'),status); /* Set up the socket for the Server */ server$socket$ovl.psb$slot = SERVER$PSB$SLOT; /* Server PSB slot */ server$socket$ovl.port$id = SERVER$PORT$ID; /* Server Port ID */ /* Create a default socket to get to the board in slot SERVER$PSB$SLOT. */ CALL rq$connect (port$tkn,server$socket,@status); CALL check$exception (@(10,'rq$connect'),status); /* Create a buffer pool object */ bufpool$tkn = rq$create$buffer$pool (30,0,@status); CALL check$exception (@(21,'rq$create$buffer$pool'),status); /* Attach the buffer pool to a default socket */ CALL rq$attach$buffer$pool (bufpool$tkn,port$tkn,@status); CALL check$exception (@(21,'rq$attach$buffer$pool'),status); /* Create and release buffers to the buffer pool */ DO count = 0 TO 5; /* Create a buffer */ segment$tkn = rq$create$segment (1024,@status); CALL check$exception (@(17,'rq$create$segment'),status); /* Release the buffer to the buffer pool */ CALL rq$release$buffer (bufpool$tkn,segment$tkn,0,@status); CALL check$exception (@(17,'rq$release$buffer'),status); END; /* DO count = 0 TO 5 */ DO count = 0 TO 7; /* Get user message */ CALL rq$c$send$co$response (@response$p,21,@message,@status); CALL check$exception (@(21,'rq$c$send$co$response'),status); /* Encrypt the message before sending it */ index = 1; /* Skip the count byte */ DO WHILE ((response$p(index) <> CR) AND (index < 255)); response$p(index) = encrypt (response$p(index)); index = index + 1; END; /* Send an asynchronous message to the Server */ trans$id = rq$send (port$tkn,server$socket,@control$msg,@response$p, DWORD(response$p(0))+1,async$mode,@status); CALL check$exception (@(7,'rq$send'),status); not$ok = TRUE; /* Ensure that the transaction ID of the message being received * is the same as the transaction ID of the message sent. */ DO WHILE (not$ok); /* Receive the transmission message for the asynchronous * rq$send. */ in$buff$ptr = rq$receive (port$tkn,WAIT$FOREVER, @msg$info$struc,@status); CALL check$exception (@(10,'rq$receive'),status); /* Check if the transaction ID is the same as the transaction * ID of the message sent. If it is, this is the transmission * message for that asynchronous rq$send. */ IF (msg$info$struc.trans$id = trans$id) THEN not$ok = FALSE; END; /* DO WHILE (not$ok) */ /* Get the decrypted message back from the Server */ in$buff$ptr = rq$receive (port$tkn,WAIT$FOREVER,@msg$info$struc, @status); CALL check$exception (@(10,'rq$receive'),status); /* Display the received message */ CALL rq$c$send$co$response (NIL,0,@message2,@status); CALL check$exception (@(21,'rq$c$send$co$response'),status); /* The message is in the data buffer */ CALL rq$c$send$co$response (NIL,0,in$buff$ptr,@status); CALL check$exception (@(21,'rq$c$send$co$response'),status); /* Force a new line */ CALL rq$c$send$co$response (NIL,0,@message3,@status); CALL check$exception (@(21,'rq$c$send$co$response'),status); /* Find the buffer token */ buffer$tkn = selector$of (in$buff$ptr); /* Release the buffer back into the buffer pool */ CALL rq$release$buffer (buf$pool$tkn,buffer$tkn,0,@status); CALL check$exception (@(17,'rq$release$buffer'),status); END; /* DO count = 0 TO 7 */ /* Clean up */ CALL rq$delete$port (port$tkn,@status); CALL check$exception (@(14,'rq$delete$port'),status); /* Exit gracefully */ CALL rq$exit$io$job (0,NIL,@status); CALL check$exception (@(14,'rq$exit$io$job'),status); END client; /* End of module */