NOSEQCON.CPP 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: F:\projects\c&c\vcs\code\noseqcon.cpv 1.10 01 Mar 1996 18:08:30 JOE_BOSTIC $ */
  19. /***************************************************************************
  20. ** 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 **
  21. ***************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : SEQCONN.CPP *
  26. * *
  27. * Programmer : Bill Randolph *
  28. * *
  29. * Start Date : December 20, 1994 *
  30. * *
  31. * Last Update : April 9, 1995 [BRR] *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * Functions: *
  35. * NonSequencedConnClass::NonSequencedConnClass -- class constructor *
  36. * NonSequencedConnClass::~NonSequencedConnClass -- class destructor *
  37. * NonSequencedConnClass::Init -- Initializes connection queue to empty *
  38. * NonSequencedConnClass::Send_Packet -- adds a packet to the send queue *
  39. * NonSequencedConnClass::Receive_Packet -- adds packet to receive queue *
  40. * NonSequencedConnClass::Get_Packet -- gets a packet from receive queue *
  41. * NonSequencedConnClass::Service_Send_Queue -- services the send queue *
  42. * NonSequencedConnClass::Service_Receive_Queue -- services recieve queue*
  43. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  44. #include "function.h"
  45. /***************************************************************************
  46. * NonSequencedConnClass::NonSequencedConnClass -- class constructor *
  47. * *
  48. * INPUT: *
  49. * numsend desired # of entries for the send queue *
  50. * numreceive desired # of entries for the recieve queue *
  51. * maxlen max length of an application packet *
  52. * magicnum the packet "magic number" for this connection *
  53. * retry_delta the time to wait between sends *
  54. * max_retries the max # of retries allowed for a packet *
  55. * (-1 means retry forever, based on this parameter) *
  56. * timeout the max amount of time before we give up on a packet *
  57. * (-1 means retry forever, based on this parameter) *
  58. * *
  59. * OUTPUT: *
  60. * none. *
  61. * *
  62. * WARNINGS: *
  63. * none. *
  64. * *
  65. * HISTORY: *
  66. * 12/20/1994 BR : Created. *
  67. *=========================================================================*/
  68. NonSequencedConnClass::NonSequencedConnClass (int numsend, int numreceive,
  69. int maxlen, unsigned short magicnum, unsigned long retry_delta,
  70. unsigned long max_retries, unsigned long timeout) :
  71. ConnectionClass (maxlen, magicnum, retry_delta, max_retries, timeout)
  72. {
  73. /*------------------------------------------------------------------------
  74. Allocate the packet Queue. This will store incoming packets (which will
  75. be placed there by the Connection Manager), and outgoing packets (which
  76. are placed there by this class when it "sends" a packet).
  77. ------------------------------------------------------------------------*/
  78. Queue = new CommBufferClass (numsend, numreceive, MaxPacketLen);
  79. }
  80. /***************************************************************************
  81. * NonSequencedConnClass::~NonSequencedConnClass -- class destructor *
  82. * *
  83. * INPUT: *
  84. * none. *
  85. * *
  86. * OUTPUT: *
  87. * none. *
  88. * *
  89. * WARNINGS: *
  90. * none. *
  91. * *
  92. * HISTORY: *
  93. * 12/20/1994 BR : Created. *
  94. *=========================================================================*/
  95. NonSequencedConnClass::~NonSequencedConnClass ()
  96. {
  97. delete Queue;
  98. }
  99. /***************************************************************************
  100. * NonSequencedConnClass::Init -- Initializes connection queue to empty *
  101. * *
  102. * INPUT: *
  103. * none. *
  104. * *
  105. * OUTPUT: *
  106. * none. *
  107. * *
  108. * WARNINGS: *
  109. * none. *
  110. * *
  111. * HISTORY: *
  112. * 12/20/1994 BR : Created. *
  113. *=========================================================================*/
  114. void NonSequencedConnClass::Init (void)
  115. {
  116. NumRecNoAck = 0;
  117. NumRecAck = 0;
  118. NumSendNoAck = 0;
  119. NumSendAck = 0;
  120. LastSeqID = 0xffffffff;
  121. LastReadID = 0xffffffff;
  122. Queue->Init();
  123. }
  124. /***************************************************************************
  125. * NonSequencedConnClass::Send_Packet -- adds a packet to the send queue *
  126. * *
  127. * This routine prefixes the given buffer with a CommHeaderType and *
  128. * queues the resulting packet into the Send Queue. (It's actually the *
  129. * Service() routine that handles the hardware-dependent Send of the data).*
  130. * The packet's MagicNumber, Code, and PacketID are set here. *
  131. * *
  132. * INPUT: *
  133. * buf buffer to send *
  134. * buflen length of buffer *
  135. * ack_req true = ACK is required for this packet; false = isn't *
  136. * *
  137. * OUTPUT: *
  138. * 1 = packet was queue'd OK, 0 = wasn't *
  139. * *
  140. * WARNINGS: *
  141. * none. *
  142. * *
  143. * HISTORY: *
  144. * 12/20/1994 BR : Created. *
  145. *=========================================================================*/
  146. int NonSequencedConnClass::Send_Packet (void * buf, int buflen, int ack_req)
  147. {
  148. /*........................................................................
  149. Set the magic # for the packet
  150. ........................................................................*/
  151. ((CommHeaderType *)PacketBuf)->MagicNumber = MagicNum;
  152. /*........................................................................
  153. Set the packet Code: DATA_ACK if it requires an ACK, NOACK if it doesn't
  154. Set the packet ID to the appropriate counter value.
  155. ........................................................................*/
  156. if (ack_req) {
  157. ((CommHeaderType *)PacketBuf)->Code = PACKET_DATA_ACK;
  158. ((CommHeaderType *)PacketBuf)->PacketID = NumSendAck;
  159. } else {
  160. ((CommHeaderType *)PacketBuf)->Code = PACKET_DATA_NOACK;
  161. ((CommHeaderType *)PacketBuf)->PacketID = NumSendNoAck;
  162. }
  163. /*........................................................................
  164. Now build the packet
  165. ........................................................................*/
  166. memcpy(PacketBuf + sizeof(CommHeaderType), buf, buflen);
  167. /*........................................................................
  168. Add it to the queue.
  169. ........................................................................*/
  170. if (Queue->Queue_Send(PacketBuf,buflen + sizeof(CommHeaderType))) {
  171. if (ack_req) {
  172. // Smart_Printf( "Packet ack Queued ID %d \n", ((CommHeaderType *)PacketBuf)->PacketID );
  173. NumSendAck++;
  174. } else {
  175. // Smart_Printf( "Packet noack Queued ID %d \n", ((CommHeaderType *)PacketBuf)->PacketID );
  176. NumSendNoAck++;
  177. }
  178. return(true);
  179. } else {
  180. // Smart_Printf( "Packet not Queued ID %d \n", ((CommHeaderType *)PacketBuf)->PacketID );
  181. return(false);
  182. }
  183. }
  184. /***************************************************************************
  185. * NonSequencedConnClass::Receive_Packet -- adds packet to the receive queue *
  186. * *
  187. * INPUT: *
  188. * buf buffer to process (already includes CommHeaderType) *
  189. * buflen length of buffer to process *
  190. * *
  191. * OUTPUT: *
  192. * 1 = packet was processed OK, 0 = error *
  193. * *
  194. * WARNINGS: *
  195. * none. *
  196. * *
  197. * HISTORY: *
  198. * 12/20/1994 BR : Created. *
  199. *=========================================================================*/
  200. int NonSequencedConnClass::Receive_Packet (void * buf, int buflen)
  201. {
  202. CommHeaderType *packet; // ptr to packet header
  203. SendQueueType *send_entry; // ptr to send entry header
  204. ReceiveQueueType *rec_entry; // ptr to recv entry header
  205. CommHeaderType *entry_data; // ptr to queue entry data
  206. CommHeaderType ackpacket; // ACK packet to send
  207. int i;
  208. int save_packet = 1; // 0 = this is a resend
  209. int found;
  210. /*
  211. --------------------------- Check the magic # ----------------------------
  212. */
  213. packet = (CommHeaderType *)buf;
  214. if (packet->MagicNumber != MagicNum) {
  215. // Smart_Printf( "Bad Magic Number\n" );
  216. return(false);
  217. }
  218. /*------------------------------------------------------------------------
  219. Handle an incoming ACK
  220. ------------------------------------------------------------------------*/
  221. if (packet->Code == PACKET_ACK) {
  222. for (i = 0; i < Queue->Num_Send(); i++) {
  223. /*
  224. ....................... Get queue entry ptr ........................
  225. */
  226. send_entry = Queue->Get_Send(i);
  227. /*
  228. ............... If ptr is valid, get ptr to its data ...............
  229. */
  230. if (send_entry != NULL) {
  231. entry_data = (CommHeaderType *)send_entry->Buffer;
  232. /*
  233. .............. If ACK is for this entry, mark it ................
  234. */
  235. if (packet->PacketID==entry_data->PacketID &&
  236. entry_data->Code == PACKET_DATA_ACK) {
  237. // Smart_Printf( "Received ACK for %d \n", packet->PacketID );
  238. send_entry->IsACK = 1;
  239. break;
  240. }
  241. }
  242. }
  243. //{
  244. // if (i == Queue->Num_Send() ) {
  245. // Smart_Printf( "Received bad ACK for %d \n", packet->PacketID );
  246. // }
  247. //}
  248. return(true);
  249. }
  250. /*------------------------------------------------------------------------
  251. Handle an incoming PACKET_DATA_NOACK packet
  252. ------------------------------------------------------------------------*/
  253. else if (packet->Code == PACKET_DATA_NOACK) {
  254. /*---------------------------------------------------------------------
  255. If there's only one slot left, don't tie up the queue with this packet
  256. ---------------------------------------------------------------------*/
  257. if (Queue->Max_Receive() - Queue->Num_Receive() <= 1) {
  258. // Smart_Printf( "Only one slot left don't tie up with DATA NOACK packet %d \n", packet->PacketID );
  259. return(false);
  260. }
  261. /*---------------------------------------------------------------------
  262. Error if we can't queue the packet
  263. ---------------------------------------------------------------------*/
  264. if (!Queue->Queue_Receive (buf, buflen)) {
  265. // Smart_Printf( "Can't Queue the packet %d \n", packet->PacketID );
  266. return(false);
  267. }
  268. // Smart_Printf( "Queued DATA NOACK for %d \n", packet->PacketID );
  269. NumRecNoAck++;
  270. return(true);
  271. }
  272. /*------------------------------------------------------------------------
  273. Handle an incoming PACKET_DATA_ACK packet
  274. ------------------------------------------------------------------------*/
  275. else if (packet->Code == PACKET_DATA_ACK) {
  276. // Smart_Printf( "Looking at ID %d, LastSeqID=%d \n", packet->PacketID, LastSeqID );
  277. /*....................................................................
  278. If this is a packet requires an ACK, and it's ID is older than our
  279. "oldest" ID, we know it's a resend; send an ACK, but don't queue it
  280. ....................................................................*/
  281. if (packet->PacketID <= LastSeqID && LastSeqID != 0xffffffff) {
  282. // Smart_Printf( "Older than oldest\n" );
  283. save_packet = 0;
  284. }
  285. /*....................................................................
  286. Otherwise, scan the queue for this entry; if it's found, it's a
  287. resend, so don't save it.
  288. ....................................................................*/
  289. else {
  290. save_packet = 1;
  291. for (i = 0; i < Queue->Num_Receive(); i++) {
  292. rec_entry = Queue->Get_Receive(i);
  293. if (rec_entry) {
  294. entry_data = (CommHeaderType *)rec_entry->Buffer;
  295. /*...........................................................
  296. Packet is found; it's a resend
  297. ...........................................................*/
  298. if (entry_data->Code == PACKET_DATA_ACK &&
  299. entry_data->PacketID == packet->PacketID) {
  300. // Smart_Printf( "It's a resend\n" );
  301. save_packet = 0;
  302. break;
  303. }
  304. }
  305. }
  306. } /* end of scan for resend */
  307. /*---------------------------------------------------------------------
  308. Queue the packet & update our LastSeqID value.
  309. ---------------------------------------------------------------------*/
  310. if (save_packet) {
  311. /*------------------------------------------------------------------
  312. If there's only one slot left, make sure we only put a packet in it if
  313. this packet will let us increment our LastSeqID; otherwise, we'll get
  314. stuck, forever unable to increment LastSeqID.
  315. ------------------------------------------------------------------*/
  316. if (Queue->Max_Receive() - Queue->Num_Receive() <= 1) {
  317. if (packet->PacketID != (LastSeqID + 1) ) {
  318. // Smart_Printf( "One slot left not what we looking for max=%d,num=%d \n",
  319. // Queue->Max_Receive(), Queue->Num_Receive() );
  320. return(0);
  321. }
  322. }
  323. /*------------------------------------------------------------------
  324. If we can't queue the packet, return; don't send an ACK.
  325. ------------------------------------------------------------------*/
  326. if (!Queue->Queue_Receive (buf, buflen)) {
  327. // Smart_Printf( "unable to queue packet\n" );
  328. return(0);
  329. }
  330. NumRecAck++;
  331. /*------------------------------------------------------------------
  332. Update our LastSeqID value if we can. Anything less than LastSeqID
  333. we'll know is a resend.
  334. ------------------------------------------------------------------*/
  335. if (packet->PacketID == (LastSeqID + 1)) {
  336. LastSeqID = packet->PacketID;
  337. /*............................................................
  338. Now that we have a new 'LastSeqID', search our Queue to see if
  339. the next ID is there; if so, keep checking for the next one;
  340. break only when the next one isn't found. This forces
  341. LastSeqID to be the largest possible value.
  342. ............................................................*/
  343. do {
  344. found = 0;
  345. for (i = 0; i < Queue->Num_Receive(); i++) {
  346. rec_entry = Queue->Get_Receive(i);
  347. if (rec_entry) {
  348. entry_data = (CommHeaderType *)rec_entry->Buffer;
  349. /*......................................................
  350. Entry is found
  351. ......................................................*/
  352. if (entry_data->Code == PACKET_DATA_ACK &&
  353. entry_data->PacketID == (LastSeqID + 1)) {
  354. LastSeqID = entry_data->PacketID;
  355. found = 1;
  356. break;
  357. }
  358. }
  359. }
  360. } while (found);
  361. }
  362. } /* end of save packet */
  363. /*---------------------------------------------------------------------
  364. Send an ACK, regardless of whether this was a resend or not.
  365. ---------------------------------------------------------------------*/
  366. ackpacket.MagicNumber = Magic_Num();
  367. ackpacket.Code = PACKET_ACK;
  368. ackpacket.PacketID = packet->PacketID;
  369. // Smart_Printf( "Sending ACK for %d \n", packet->PacketID );
  370. Send ((char *)&ackpacket, sizeof(CommHeaderType));
  371. return(true);
  372. } else {
  373. // Smart_Printf( "invalid packet type %d \n", packet->Code );
  374. }
  375. return(false);
  376. }
  377. /***************************************************************************
  378. * NonSequencedConnClass::Get_Packet -- gets a packet from receive queue *
  379. * *
  380. * INPUT: *
  381. * buf location to store buffer *
  382. * buflen filled in with length of 'buf' *
  383. * *
  384. * OUTPUT: *
  385. * 1 = packet was read, 0 = wasn't *
  386. * *
  387. * WARNINGS: *
  388. * none. *
  389. * *
  390. * HISTORY: *
  391. * 12/20/1994 BR : Created. *
  392. *=========================================================================*/
  393. int NonSequencedConnClass::Get_Packet (void * buf, int *buflen)
  394. {
  395. ReceiveQueueType *rec_entry; // ptr to receive entry header
  396. int packetlen; // size of received packet
  397. CommHeaderType *entry_data;
  398. int i;
  399. /*------------------------------------------------------------------------
  400. Ensure that we read the packets in order. LastReadID is the ID of the
  401. last PACKET_DATA_ACK packet we read.
  402. ------------------------------------------------------------------------*/
  403. for (i = 0; i < Queue->Num_Receive(); i++) {
  404. rec_entry = Queue->Get_Receive(i);
  405. /*.....................................................................
  406. Only read this entry if it hasn't been yet
  407. .....................................................................*/
  408. if (rec_entry && rec_entry->IsRead==0) {
  409. entry_data = (CommHeaderType *)rec_entry->Buffer;
  410. /*..................................................................
  411. If this is a DATA_ACK packet, its ID must be one greater than
  412. the last one we read.
  413. ..................................................................*/
  414. if ( (entry_data->Code == PACKET_DATA_ACK) &&
  415. (entry_data->PacketID == (LastReadID + 1))) {
  416. LastReadID = entry_data->PacketID;
  417. rec_entry->IsRead = 1;
  418. packetlen = rec_entry->BufLen - sizeof(CommHeaderType);
  419. if (packetlen > 0) {
  420. memcpy(buf, rec_entry->Buffer + sizeof(CommHeaderType), packetlen);
  421. }
  422. (*buflen) = packetlen;
  423. return(true);
  424. }
  425. /*..................................................................
  426. If this is a DATA_NOACK packet, who cares what the ID is?
  427. ..................................................................*/
  428. else if (entry_data->Code == PACKET_DATA_NOACK) {
  429. rec_entry->IsRead = 1;
  430. packetlen = rec_entry->BufLen - sizeof(CommHeaderType);
  431. if (packetlen > 0) {
  432. memcpy(buf, rec_entry->Buffer + sizeof(CommHeaderType), packetlen);
  433. }
  434. (*buflen) = packetlen;
  435. return(true);
  436. }
  437. }
  438. }
  439. return(false);
  440. }
  441. /***************************************************************************
  442. * NonSequencedConnClass::Service_Send_Queue -- services the send queue *
  443. * *
  444. * INPUT: *
  445. * none. *
  446. * *
  447. * OUTPUT: *
  448. * 1 = OK, 0 = error *
  449. * *
  450. * WARNINGS: *
  451. * none. *
  452. * *
  453. * HISTORY: *
  454. * 12/20/1994 BR : Created. *
  455. *=========================================================================*/
  456. int NonSequencedConnClass::Service_Send_Queue (void)
  457. {
  458. int i;
  459. int num_entries;
  460. SendQueueType *send_entry; // ptr to send queue entry
  461. CommHeaderType *packet_hdr; // packet header
  462. unsigned long curtime; // current time
  463. int bad_conn = 0;
  464. /*------------------------------------------------------------------------
  465. Remove any ACK'd packets from the queue
  466. ------------------------------------------------------------------------*/
  467. for (i = 0; i < Queue->Num_Send(); i++) {
  468. /*
  469. ------------------------- Get this queue entry ------------------------
  470. */
  471. send_entry = Queue->Get_Send(i);
  472. /*
  473. ---------------- If ACK has been received, unqueue it -----------------
  474. */
  475. if (send_entry->IsACK) {
  476. /*
  477. ................ Update this queue's response time .................
  478. */
  479. packet_hdr = (CommHeaderType *)send_entry->Buffer;
  480. if (packet_hdr->Code == PACKET_DATA_ACK) {
  481. Queue->Add_Delay(Time() - send_entry->FirstTime);
  482. }
  483. /*
  484. ....................... unqueue the packet .........................
  485. */
  486. Queue->UnQueue_Send(NULL,NULL,i);
  487. i--;
  488. }
  489. }
  490. /*------------------------------------------------------------------------
  491. Loop through all entries in the Send queue. [Re]Send any entries that
  492. need it.
  493. ------------------------------------------------------------------------*/
  494. num_entries = Queue->Num_Send();
  495. for (i = 0; i < num_entries; i++) {
  496. send_entry = Queue->Get_Send(i);
  497. if (send_entry->IsACK) {
  498. continue;
  499. }
  500. /*.....................................................................
  501. Only send the message if time has elapsed. (The message's Time
  502. fields are init'd to 0 when a message is queue'd or unqueue'd, so the
  503. first time through, the delta time will appear large.)
  504. .....................................................................*/
  505. curtime = Time();
  506. if (curtime - send_entry->LastTime > RetryDelta) {
  507. /*
  508. ......................... Send the message .........................
  509. */
  510. #if(0)
  511. {
  512. packet_hdr = (CommHeaderType *)send_entry->Buffer;
  513. if (send_entry->SendCount) {
  514. if (packet_hdr->Code == PACKET_DATA_NOACK) {
  515. // Smart_Printf( "Resending DATA NOACK for %d \n", packet_hdr->PacketID );
  516. } else {
  517. if (packet_hdr->Code == PACKET_DATA_ACK) {
  518. // Smart_Printf( "Resending DATA ACK for %d \n", packet_hdr->PacketID );
  519. }
  520. }
  521. } else {
  522. if (packet_hdr->Code == PACKET_DATA_NOACK) {
  523. // Smart_Printf( "Sending DATA NOACK for %d \n", packet_hdr->PacketID );
  524. } else {
  525. if (packet_hdr->Code == PACKET_DATA_ACK) {
  526. // Smart_Printf( "Sending DATA ACK for %d \n", packet_hdr->PacketID );
  527. }
  528. }
  529. }
  530. }
  531. #endif
  532. Send (send_entry->Buffer, send_entry->BufLen);
  533. /*
  534. ....................... Fill in Time fields ........................
  535. */
  536. send_entry->LastTime = curtime;
  537. if (send_entry->SendCount==0) {
  538. send_entry->FirstTime = curtime;
  539. /*...............................................................
  540. If this is the 1st time we're sending this packet, and it doesn't
  541. require an ACK, mark it as ACK'd; then, the next time through,
  542. it will just be removed from the queue.
  543. ...............................................................*/
  544. packet_hdr = (CommHeaderType *)send_entry->Buffer;
  545. if (packet_hdr->Code == PACKET_DATA_NOACK) {
  546. send_entry->IsACK = 1;
  547. }
  548. }
  549. /*
  550. ......................... Update SendCount .........................
  551. */
  552. send_entry->SendCount++;
  553. /*..................................................................
  554. Perform error detection, based on either MaxRetries or Timeout
  555. ..................................................................*/
  556. if (MaxRetries != -1 && send_entry->SendCount > MaxRetries) {
  557. // Smart_Printf( "Max Retries!!! %d !!! \n", MaxRetries );
  558. bad_conn = 1;
  559. }
  560. if (Timeout != -1 &&
  561. (send_entry->LastTime - send_entry->FirstTime) > Timeout) {
  562. // Smart_Printf( "Timed out!!! Time %d, Timeout %d, buflen %d !!! \n",
  563. // (send_entry->LastTime - send_entry->FirstTime), Timeout,
  564. // send_entry->BufLen );
  565. bad_conn = 1;
  566. }
  567. }
  568. }
  569. /*------------------------------------------------------------------------
  570. If the connection is going bad, return an error
  571. ------------------------------------------------------------------------*/
  572. if (bad_conn) {
  573. // Smart_Printf( "Connection going bad!!! \n" );
  574. return(false);
  575. } else {
  576. return(true);
  577. }
  578. }
  579. /***************************************************************************
  580. * NonSequencedConnClass::Service_Receive_Queue -- services recieve queue *
  581. * *
  582. * INPUT: *
  583. * none. *
  584. * *
  585. * OUTPUT: *
  586. * 1 = OK, 0 = error *
  587. * *
  588. * WARNINGS: *
  589. * none. *
  590. * *
  591. * HISTORY: *
  592. * 12/20/1994 BR : Created. *
  593. *=========================================================================*/
  594. int NonSequencedConnClass::Service_Receive_Queue (void)
  595. {
  596. ReceiveQueueType *rec_entry; // ptr to receive entry header
  597. CommHeaderType *packet_hdr; // packet header
  598. int i;
  599. /*------------------------------------------------------------------------
  600. Remove all dead packets.
  601. PACKET_DATA_NOACK: if it's been read, throw it away.
  602. PACKET_DATA_ACK: if it's been read, and its ID is older than LastSeqID,
  603. throw it away.
  604. ------------------------------------------------------------------------*/
  605. for (i = 0; i < Queue->Num_Receive(); i++) {
  606. rec_entry = Queue->Get_Receive(i);
  607. if (rec_entry->IsRead) {
  608. packet_hdr = (CommHeaderType *)(rec_entry->Buffer);
  609. if (packet_hdr->Code == PACKET_DATA_NOACK) {
  610. Queue->UnQueue_Receive(NULL,NULL,i);
  611. i--;
  612. } else {
  613. if (packet_hdr->PacketID < LastSeqID) {
  614. Queue->UnQueue_Receive(NULL,NULL,i);
  615. i--;
  616. }
  617. }
  618. }
  619. }
  620. return(true);
  621. }