home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_sndstream.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  1.7 KB  |  84 lines

  1. # include  "d_returns.h"
  2.  
  3. extern char  d_xqueue[], *d_xqpt;
  4. extern int  d_xqcnt, d_maxtext;
  5.   
  6. /*
  7.  *     D_SNDSTREAM
  8.  *
  9.  *    this routine is called to send data
  10.  *    to the other side without necessarily
  11.  *    implying any packet boundaries.
  12.  *
  13.  *     buffer -- pointer to the data to be sent
  14.  *
  15.  *     nbytes -- number of bytes to be sent
  16.  */
  17.  
  18. d_snstream(buffer, nbytes)
  19.   char  *buffer;
  20.   int  nbytes;
  21.     {
  22.     register int  length, result;
  23.     register char  *bp;
  24.  
  25. #ifdef D_DBGLOG
  26.     d_dbglog("d_snstream", "sending  '%.*s'", nbytes, buffer);
  27. #endif D_DBGLOG
  28.  
  29.     bp = buffer;
  30.  
  31.     while (nbytes--)
  32.       {
  33.       length = d_ccode(*bp & 0177, d_xqpt);
  34.  
  35. /*  if the encoding of this character will overflow the text, send off what  */
  36. /*  we've already got.                                                       */
  37.  
  38.       if ((length + d_xqcnt) > d_maxtext)
  39.         {
  40.     /*  Note that this does not actually send the character that
  41.      *  would overflow the queue.  It never increments the pointer.
  42.      *  It overwrites the queued char(s) with a null.  It resets
  43.      *  (adds 1 to) the nbyte counter.  The continue causes it
  44.      *  to requeue the same char.
  45.      */
  46.         *d_xqpt = '\0';
  47.  
  48.     if ((result = d_sndata(0)) < 0)
  49.           return(result);
  50.  
  51.         nbytes++;
  52.         continue;
  53.         }
  54.  
  55. /*  otherwise adjust the count and pointers  */
  56.  
  57.       d_xqcnt += length;
  58.       d_xqpt += length;
  59.       bp++;
  60.       }
  61.  
  62.     return(D_OK);
  63.     }
  64.  
  65. /*
  66.  *     D_SNDEOT
  67.  *
  68.  *     this routine is called to flush the transmit buffer and mark the
  69.  *     packet with an EOT
  70.  */
  71.  
  72. d_sneot()
  73.     {
  74.     register int  result;
  75.  
  76.     *d_xqpt = '\0';
  77. #ifdef D_DBGLOG
  78.     d_dbglog("d_sneot", "packet '%s'", d_xqueue);
  79. #endif D_DBGLOG
  80.  
  81.     result = d_sndata(1);
  82.     return(result);
  83.     }
  84.