$title('nsrcvmsg - receive message using the nameserver to catalog receiving socket') $compact nsrcvmsg: DO; $include(:rmx:inc/rmxplm.ext) $include(dcom.ext) $include(dcom.lit) $include(:rmx:inc/error.lit) $include(err.ext) $include(nserv.ext) $include(nclient.lit) $include(nstabl.lit) /******************************************************************** * * MODULE NAME: nsrcvmsg * * DESCRIPTION: This module and nssndmsg demonstrate the nameserver.Create * a port, enter the socket in the nameserver table and * wait for a message in rmx string format. Write the message * to the console, release the buffer associated with the message, * delete the socket from the nameserver and exit. * *********************************************************************/ DECLARE /* Literals */ RELFLAGS LITERALLY '0', /* buffer, delete if pool full flags */ TIMETOWAIT LITERALLY '08000H', /* time to wait for response from server */ NOEXCEPT LITERALLY '0'; /* no exception handling by system */ DECLARE /* Global vars */ status WORD, port_attrs STRUCTURE( /* contains port attributes */ port_id WORD, type BYTE, reserved BYTE, queue_size WORD, reserved1 WORD, reserved2 WORD, sink_port TOKEN, def_rem_sock DWORD, buffer_pool TOKEN, flags WORD, reserved3 BYTE), port_t TOKEN, /* Token for local port */ info rec_info, /* info block on message received */ bpool TOKEN, /* buffer pool */ b_sel SELECTOR, server_host_id WORD, /* host id of nameserver */ loc_socket socket, /* socket used to receive message */ loc_sock DWORD /* dword alias for loc_socket */ AT (@loc_socket), loc_host_id WORD, buf_tok TOKEN AT (@b_sel), /* token for buffer holding message */ result BYTE, /* result of requested operation */ msg_ptr POINTER; /* pointer to received message */ CALL set$exception(NOEXCEPT); port_t = get$dport(0, @bpool, CHAIN, @status); CALL error$check(100, status); server_host_id = get_host_id(TIMETOWAIT, @status); IF server_host_id = SERVERNOTFOUND THEN DO; CALL rq$csend$co$response(NIL, 0, @(25,'Remote Server Not Found',0dh,0ah), @status); CALL rq$exit$io$job(0,NIL,@status); END; loc_host_id = rq$get$host$id(@status); CALL error$check(110, status); CALL rq$get$port$attributes(port_t, @port_attrs, @status); CALL error$check(115, status); loc_socket.host_id = loc_host_id; loc_socket.port_id = port_attrs.port_id; result = insert_name(server_host_id, @(8,'receiver'), loc_sock, TIMETOWAIT, @status); IF result <> REQCOMPLETED THEN DO; CALL rq$csend$co$response(NIL, 0, @(15,'Insert Failed',0dh,0ah), @status); CALL rq$exit$io$job(0,NIL,@status); END; msg_ptr = rq$receive(port_t, WAITFOREVER, @info, @status); CALL error$check(120, status); call rqc$send$co$response(NIL, 0, msg_ptr, @status); CALL error$check(130, status); b_sel = selector$of(msg_ptr); call rq$release$buffer(bpool, buf_tok, RELFLAGS, @status); CALL error$check(140, status); result = delete_name(server_host_id, @(8,'receiver'), TIMETOWAIT, @status); CALL rq$exit$io$job(0,NIL,@status); END nsrcvmsg;