COMBUF.H 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/COMBUF.H 1 3/03/97 10:24a Joe_bostic $ */
  15. /***************************************************************************
  16. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  17. ***************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : COMBUF.H *
  22. * *
  23. * Programmer : Bill Randolph *
  24. * *
  25. * Start Date : December 19, 1994 *
  26. * *
  27. * Last Update : April 1, 1995 [BR] *
  28. * *
  29. *-------------------------------------------------------------------------*
  30. * *
  31. * This class's job is to store outgoing messages & incoming messages, *
  32. * and serves as a storage area for various flags for ACK & Retry logic. *
  33. * *
  34. * This class stores buffers in a non-sequenced order; it allows freeing *
  35. * any entry, so the buffers can be kept clear, even if packets come in *
  36. * out of order. *
  37. * *
  38. * The class also contains routines to maintain a cumulative response time *
  39. * for this queue. It's up to the caller to call Add_Delay() whenever *
  40. * it detects that an outgoing message has been ACK'd; this class adds *
  41. * that delay into a computed average delay over the last few message *
  42. * delays. *
  43. * *
  44. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  45. #ifndef COMBUF_H
  46. #define COMBUF_H
  47. /*
  48. ********************************** Defines **********************************
  49. */
  50. /*---------------------------------------------------------------------------
  51. This is one output queue entry
  52. ---------------------------------------------------------------------------*/
  53. typedef struct {
  54. unsigned int IsActive : 1; // 1 = this entry is ready to be processed
  55. unsigned int IsACK : 1; // 1 = ACK received for this packet
  56. unsigned long FirstTime; // time this packet was first sent
  57. unsigned long LastTime; // time this packet was last sent
  58. unsigned long SendCount; // # of times this packet has been sent
  59. int BufLen; // size of the packet stored in this entry
  60. char *Buffer; // the data packet
  61. int ExtraLen; // size of extra data
  62. char *ExtraBuffer; // extra data buffer
  63. } SendQueueType;
  64. /*---------------------------------------------------------------------------
  65. This is one input queue entry
  66. ---------------------------------------------------------------------------*/
  67. typedef struct {
  68. unsigned int IsActive : 1; // 1 = this entry is ready to be processed
  69. unsigned int IsRead : 1; // 1 = caller has read this entry
  70. unsigned int IsACK : 1; // 1 = ACK sent for this packet
  71. int BufLen; // size of the packet stored in this entry
  72. char *Buffer; // the data packet
  73. int ExtraLen; // size of extra data
  74. char *ExtraBuffer; // extra data buffer
  75. } ReceiveQueueType;
  76. /*
  77. ***************************** Class Declaration *****************************
  78. */
  79. class CommBufferClass
  80. {
  81. /*
  82. ---------------------------- Public Interface ----------------------------
  83. */
  84. public:
  85. /*
  86. ....................... Constructor/Destructor ........................
  87. */
  88. CommBufferClass(int numsend, int numrecieve, int maxlen,
  89. int extralen = 0);
  90. virtual ~CommBufferClass();
  91. void Init(void);
  92. void Init_Send_Queue(void);
  93. /*
  94. ......................... Send Queue routines .........................
  95. */
  96. int Queue_Send(void *buf, int buflen, void *extrabuf = NULL,
  97. int extralen = 0);
  98. int UnQueue_Send(void *buf, int *buflen, int index,
  99. void *extrabuf = NULL, int *extralen = NULL);
  100. int Num_Send(void) {return (SendCount);} // # entries in queue
  101. int Max_Send(void) { return (MaxSend);} // max # send queue entries
  102. SendQueueType * Get_Send(int index); // random access to queue
  103. unsigned long Send_Total(void) {return (SendTotal);}
  104. /*
  105. ....................... Receive Queue routines ........................
  106. */
  107. int Queue_Receive(void *buf, int buflen, void *extrabuf = NULL,
  108. int extralen = 0);
  109. int UnQueue_Receive(void *buf, int *buflen, int index,
  110. void *extrabuf = NULL, int *extralen = NULL);
  111. int Num_Receive(void) {return (ReceiveCount);} // # entries in queue
  112. int Max_Receive(void) { return (MaxReceive); } // max # recv queue entries
  113. ReceiveQueueType * Get_Receive(int index); // random access to queue
  114. unsigned long Receive_Total(void) {return (ReceiveTotal);}
  115. /*
  116. ....................... Response time routines ........................
  117. */
  118. void Add_Delay(unsigned long delay); // accumulates response time
  119. unsigned long Avg_Response_Time(void); // gets mean response time
  120. unsigned long Max_Response_Time(void); // gets max response time
  121. void Reset_Response_Time(void); // resets computations
  122. /*
  123. ........................ Debug output routines ........................
  124. */
  125. void Configure_Debug(int type_offset, int type_size, char **names,
  126. int namestart, int namecount);
  127. void Mono_Debug_Print(int refresh = 0);
  128. void Mono_Debug_Print2(int refresh = 0);
  129. /*
  130. --------------------------- Private Interface ----------------------------
  131. */
  132. private:
  133. /*
  134. .......................... Limiting variables .........................
  135. */
  136. int MaxSend; // max # send queue entries
  137. int MaxReceive; // max # receive queue entries
  138. int MaxPacketSize; // max size of a packet, in bytes
  139. int MaxExtraSize; // max size of extra bytes
  140. /*
  141. ....................... Response time variables .......................
  142. */
  143. unsigned long DelaySum; // sum of last 4 delay times
  144. unsigned long NumDelay; // current # delay times summed
  145. unsigned long MeanDelay; // current average delay time
  146. unsigned long MaxDelay; // max delay ever for this queue
  147. /*
  148. ........................ Send Queue variables .........................
  149. */
  150. SendQueueType * SendQueue; // incoming packets
  151. int SendCount; // # packets in the queue
  152. unsigned long SendTotal; // total # added to send queue
  153. int *SendIndex; // array of Send entry indices
  154. /*
  155. ....................... Receive Queue variables .......................
  156. */
  157. ReceiveQueueType * ReceiveQueue; // outgoing packets
  158. int ReceiveCount; // # packets in the queue
  159. unsigned long ReceiveTotal; // total # added to receive queue
  160. int *ReceiveIndex; // array of Receive entry indices
  161. /*
  162. ......................... Debugging Variables .........................
  163. */
  164. int DebugOffset; // offset into app's packet for ID
  165. int DebugSize; // size of app's ID
  166. char **DebugNames; // ptr to array of app-specific names
  167. int DebugNameStart; // number of 1st ID
  168. int DebugNameCount; // # of names in array
  169. };
  170. #endif
  171. /**************************** end of combuf.h ******************************/