home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s038 / 1.ddi / SUPP.LIF / RCVFRAG.PLM < prev    next >
Encoding:
Text File  |  1992-07-06  |  3.7 KB  |  94 lines

  1. $title('rcvfrag - receive a fragmented message')
  2. $compact
  3. /********************************************************************
  4.  *
  5.  *     MODULE NAME: rcvfrag    
  6.  *
  7.  *     DESCRIPTION: Receive a fragmented message and print the message contained
  8.  *                  at the beginning of each fragment.
  9.  *                       
  10.  *                  The task receives a printable message.  If there is not enough buffer
  11.  *                  space to receive the entire message, receive the message
  12.  *                  in fragments.  (The info data structure associated with the
  13.  *                  rq$receive call contains the message length and the transaction
  14.  *                  id necessary to receive the message in fragments.)  Print
  15.  *                  the message and send a printable message to the sender.
  16.  *             
  17.  *********************************************************************/
  18.  
  19. rcvfrag: DO;
  20.  
  21. $include(:rmx:inc/rmxplm.ext)
  22. $include(dcom.ext)
  23. $include(dcom.lit)
  24. $include(:rmx:inc/error.lit)
  25. $include(err.ext)
  26.         
  27. DECLARE       /* Literals */
  28.  
  29.     FRAGLEN     LITERALLY   '1024',    /* fragmentation buffer length */
  30.     BUFFRAG     LITERALLY   '0',       /* fragment is buffer flag */
  31.     TSTPORT     LITERALLY    '801H',    /* well-known port */
  32.     SFLAGS      LITERALLY    '00000B',  /* data buffer, synchronous flags*/
  33.     NOEXCEPT    LITERALLY   '0';       /* no exception handling by system */
  34.     
  35.  
  36. DECLARE       /* Global vars */
  37.  
  38.         status            WORD,
  39.         port_t            TOKEN,    /* Token for local port */
  40.         info              rec_info, /* info block on message received */
  41.         buf_pool          TOKEN,    /* buffer pool attached to port */
  42.         mes_buf(*)        BYTE initial (41,'This is a reply to a fragmented message',0dh,0ah),
  43.         tran_id           WORD,     /* transaction id */ 
  44.         bytes_rec         WORD,     /* number of bytes received in mess fragments */
  45.         con_buf    (20)      BYTE,     /* control message buffer */
  46.         frag_buf(FRAGLEN) BYTE,     /* fragmentation buffer */    
  47.         msg_ptr           POINTER;  /* pointer to received message */        
  48.         
  49.         
  50.     CALL set$exception(NOEXCEPT);
  51.     port_t = get$dport(TSTPORT, @buf_pool, NOCHAIN, @status);
  52.     msg_ptr = rq$receive(port_t, WAITFOREVER, @info, @status);
  53.     CALL error$check(100, status);
  54.     IF info.status = E$OK THEN DO; /* message may not be fragmented */    
  55.         CALL rqc$send$eo$response(NIL,0,msg_ptr,@status);
  56.         CALL error$check(120, status);
  57.         tran_id = rq$send$reply(port_t, info.rem$socket,
  58.                                 info.trans$id, @con_buf,
  59.                                 @mes_buf, size(mes_buf), SFLAGS, @status);
  60.         CALL error$check(130, status);
  61.         IF msg_ptr <> NIL THEN DO;
  62.             CALL rq$release$buffer(buf_pool, SELECTOR$OF(msg_ptr), (info.flags AND 3), @status);
  63.             CALL error$check(140, status);
  64.         END;                                 
  65.     END;
  66.  
  67.     
  68.     ELSE DO;
  69.         IF info.status = E$NO$LOCAL$BUFFER THEN DO;
  70.  
  71.             /* receive fragments and print message at beginning of fragments */
  72.             bytes_rec = 0;
  73.             DO WHILE bytes_rec < info.data$length;
  74.                 CALL rq$receive$fragment(port_t, info.rem$socket, info.trans$id,
  75.                                          @frag_buf, FRAGLEN, BUFFRAG, @status);
  76.                 CALL error$check(150, status);
  77.                 bytes_rec = bytes_rec + FRAGLEN;
  78.                 CALL rqc$send$eo$response(NIL,0,@frag_buf,@status);
  79.                 CALL error$check(160, status);
  80.             END;
  81.  
  82.             /* complete transaction by sending a printable message */
  83.               tran_id = rq$send$reply(port_t, info.rem$socket,
  84.                                     info.trans$id, @con_buf,
  85.                                     @mes_buf, size(mes_buf), SFLAGS, @status);
  86.             CALL error$check(170, status);
  87.         END;
  88.         ELSE
  89.             CALL rq$exit$io$job(0,NIL,@status);
  90.     END;                
  91.                                          
  92.     CALL rq$exit$io$job(0,NIL,@status);
  93. END rcvfrag;
  94.