$title('rcvfrag - receive a fragmented message') $compact /******************************************************************** * * MODULE NAME: rcvfrag * * DESCRIPTION: Receive a fragmented message and print the message contained * at the beginning of each fragment. * * The task receives a printable message. If there is not enough buffer * space to receive the entire message, receive the message * in fragments. (The info data structure associated with the * rq$receive call contains the message length and the transaction * id necessary to receive the message in fragments.) Print * the message and send a printable message to the sender. * *********************************************************************/ rcvfrag: DO; $include(:rmx:inc/rmxplm.ext) $include(dcom.ext) $include(dcom.lit) $include(:rmx:inc/error.lit) $include(err.ext) DECLARE /* Literals */ FRAGLEN LITERALLY '1024', /* fragmentation buffer length */ BUFFRAG LITERALLY '0', /* fragment is buffer flag */ TSTPORT LITERALLY '801H', /* well-known port */ SFLAGS LITERALLY '00000B', /* data buffer, synchronous flags*/ NOEXCEPT LITERALLY '0'; /* no exception handling by system */ DECLARE /* Global vars */ status WORD, port_t TOKEN, /* Token for local port */ info rec_info, /* info block on message received */ buf_pool TOKEN, /* buffer pool attached to port */ mes_buf(*) BYTE initial (41,'This is a reply to a fragmented message',0dh,0ah), tran_id WORD, /* transaction id */ bytes_rec WORD, /* number of bytes received in mess fragments */ con_buf (20) BYTE, /* control message buffer */ frag_buf(FRAGLEN) BYTE, /* fragmentation buffer */ msg_ptr POINTER; /* pointer to received message */ CALL set$exception(NOEXCEPT); port_t = get$dport(TSTPORT, @buf_pool, NOCHAIN, @status); msg_ptr = rq$receive(port_t, WAITFOREVER, @info, @status); CALL error$check(100, status); IF info.status = E$OK THEN DO; /* message may not be fragmented */ CALL rqc$send$eo$response(NIL,0,msg_ptr,@status); CALL error$check(120, status); tran_id = rq$send$reply(port_t, info.rem$socket, info.trans$id, @con_buf, @mes_buf, size(mes_buf), SFLAGS, @status); CALL error$check(130, status); IF msg_ptr <> NIL THEN DO; CALL rq$release$buffer(buf_pool, SELECTOR$OF(msg_ptr), (info.flags AND 3), @status); CALL error$check(140, status); END; END; ELSE DO; IF info.status = E$NO$LOCAL$BUFFER THEN DO; /* receive fragments and print message at beginning of fragments */ bytes_rec = 0; DO WHILE bytes_rec < info.data$length; CALL rq$receive$fragment(port_t, info.rem$socket, info.trans$id, @frag_buf, FRAGLEN, BUFFRAG, @status); CALL error$check(150, status); bytes_rec = bytes_rec + FRAGLEN; CALL rqc$send$eo$response(NIL,0,@frag_buf,@status); CALL error$check(160, status); END; /* complete transaction by sending a printable message */ tran_id = rq$send$reply(port_t, info.rem$socket, info.trans$id, @con_buf, @mes_buf, size(mes_buf), SFLAGS, @status); CALL error$check(170, status); END; ELSE CALL rq$exit$io$job(0,NIL,@status); END; CALL rq$exit$io$job(0,NIL,@status); END rcvfrag;