home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cuj9301.zip / 1101064A < prev    next >
Text File  |  1992-11-03  |  4KB  |  118 lines

  1. /* The boolean type.  */
  2. typedef int boolean;
  3. #define TRUE (1)
  4. #define FALSE (0)
  5.  
  6. /* Names for the bytes in the frame header.  */
  7. #define IFRAME_DLE (0)
  8. #define IFRAME_K (1)
  9. #define IFRAME_CHECKLOW (2)
  10. #define IFRAME_CHECKHIGH (3)
  11. #define IFRAME_CONTROL (4)
  12. #define IFRAME_XOR (5)
  13.  
  14. /* Length of the frame header.  */
  15. #define CFRAMELEN (6)
  16.  
  17. /* Macros to break apart the control bytes.  */
  18. #define CONTROL_TT(b) ((int)(((b) >> 6) & 03))
  19. #define CONTROL_XXX(b) ((int)(((b) >> 3) & 07))
  20. #define CONTROL_YYY(b) ((int)((b) & 07))
  21.  
  22. /* DLE value.  */
  23. #define DLE ('\020')
  24.  
  25. /* Get the length of a packet given a pointer to the header.  */
  26. #define CPACKLEN(z) (1 << ((z)[IFRAME_K] + 4))
  27.  
  28. /* <k> field value for a control message.  */
  29. #define KCONTROL (9)
  30.  
  31. /* Get the next sequence number given a sequence number.  */
  32. #define INEXTSEQ(i) ((i + 1) & 07)
  33.  
  34. /* Compute i1 - i2 modulo 8.  */
  35. #define CSEQDIFF(i1, i2) (((i1) + 8 - (i2)) & 07)
  36.  
  37. /* Packet types.  These are from the TT field.  */
  38. #define CONTROL (0)
  39. #define ALTCHAN (1)
  40. #define DATA (2)
  41. #define SHORTDATA (3)
  42.  
  43. /* Control types.  These are from the XXX field if the type (tt field)
  44.    is CONTROL.  */
  45. #define CLOSE (1)
  46. #define RJ (2)
  47. #define SRJ (3)
  48. #define RR (4)
  49. #define INITC (5)
  50. #define INITB (6)
  51. #define INITA (7)
  52.  
  53. /* Maximum amount of data in a single packet.  */
  54. #define CMAXDATAINDEX (8)
  55. #define CMAXDATA (1 << (CMAXDATAINDEX + 4))
  56.  
  57. /* Maximum window size.  */
  58. #define CMAXWINDOW (7)
  59.  
  60. /* The timeout to use when waiting for a packet.  Protocol parameter
  61.    ``timeout''.  */
  62. #define CTIMEOUT (10)
  63.  
  64. /* The number of times to retry waiting for a packet.  Each time the
  65.    timeout fails we send a copy of our last data packet or a reject
  66.    message for the packet we expect from the other side, depending on
  67.    whether we have any unacknowledged data.  This is the number of
  68.    times we try doing that and then waiting again.  Protocol parameter
  69.    ``retries''.  */
  70. #define CRETRIES (6)
  71.  
  72. /* Next sequence number to send.  */
  73. int iGsendseq = 1;
  74.  
  75. /* Last sequence number that has been acked.  */
  76. int iGremote_ack = 0;
  77.  
  78. /* Last sequence number to be retransmitted.  */
  79. int iGretransmit_seq = -1;
  80.  
  81. /* Last sequence number we have received.  */
  82. static int iGrecseq;
  83.  
  84. /* Remote segment size (set during protocol initialization).  This is
  85.    one less than the value in a packet header.  */
  86. int iGremote_segsize;
  87.  
  88. /* Remote packet size (set based on iGremote_segsize).  */
  89. int iGremote_packsize;
  90.  
  91. /* Remote window size (set during handshake).  */
  92. static int iGremote_winsize;
  93.  
  94. /* Timeout (seconds) for receiving a data packet.  Protocol parameter
  95.    ``timeout''.  */
  96. static int cGtimeout = CTIMEOUT;
  97.  
  98. /* Maximum number of timeouts when receiving a data packet or
  99.    acknowledgement.  Protocol parameter ``retries''.  */
  100. static int cGretries = CRETRIES;
  101.  
  102. /* Get a packet.  This is called to wait for a packet to come in when
  103.    there is nothing to send.  If freturncontrol is TRUE, this will
  104.    return after getting any control packet.  Otherwise, it will
  105.    continue to receive packets until a complete file or a complete
  106.    command has been received.  The timeout and the number of retries
  107.    are arguments.  The function returns FALSE if an error occurs or if
  108.    cretries timeouts of ctimeout seconds were exceeded.  */
  109. boolean fgwait_for_packet (boolean freturncontrol, int ctimeout,
  110.                int cretries);
  111.  
  112. /* Send data to the other system.  If the fdoread argument is TRUE,
  113.    this will also read data into abPrecbuf; fdoread is passed as TRUE
  114.    if the protocol expects data to be coming back, to make sure the
  115.    input buffer does not fill up.  Returns FALSE on error.  */
  116. boolean fsend_data (const char *zsend, int csend, boolean fdoread);
  117.  
  118.