From 49f6d0f0ca26c10f3e2aa42ef491d9a60bd1a9fc Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Thu, 7 Mar 2002 14:00:10 +0000 Subject: Introduced waitQueue to make link::transmit non-blocking. --- ncpd/link.cc | 38 ++++++++++++++++++++++++++++---------- ncpd/link.h | 3 +++ 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'ncpd') diff --git a/ncpd/link.cc b/ncpd/link.cc index 228b878..a52e3ef 100644 --- a/ncpd/link.cc +++ b/ncpd/link.cc @@ -266,10 +266,12 @@ receive(bufferStore buff) break; } pthread_mutex_unlock(&queueMutex); - if (ackFound) + if (ackFound) { // Older packets implicitely ack'ed multiAck(refstamp); - else { + // Transmit waiting packets + transmitWaitQueue(); + } else { if (verbose & LNK_DEBUG_LOG) { cout << "Link: << UNMATCHED ack seq=" << seq ; if (verbose & LNK_DEBUG_DUMP) @@ -362,6 +364,22 @@ transmitHoldQueue(int channel) transmit(*i); } +void Link:: +transmitWaitQueue() +{ + vector tmpQueue; + vector::iterator i; + + // First, move desired packets to a temporary queue + for (i = waitQueue.begin(); i != waitQueue.end(); i++) + tmpQueue.push_back(*i); + waitQueue.clear(); + // transmit the moved packets. If the backlock gets + // full, they are put into waitQueue again. + for (i = tmpQueue.begin(); i != tmpQueue.end(); i++) + transmit(*i); +} + void Link:: transmit(bufferStore buf) { @@ -375,15 +393,15 @@ transmit(bufferStore buf) pthread_mutex_unlock(&queueMutex); } else { - // Wait, until backlog is drained. + // If backlock is full, put on waitQueue int ql; - do { - pthread_mutex_lock(&queueMutex); - ql = ackWaitQueue.size(); - pthread_mutex_unlock(&queueMutex); - if (ql >= maxOutstanding) - usleep(100000); - } while (ql >= maxOutstanding); + pthread_mutex_lock(&queueMutex); + ql = ackWaitQueue.size(); + pthread_mutex_unlock(&queueMutex); + if (ql >= maxOutstanding) { + waitQueue.push_back(buf); + return; + } ackWaitQueueElement e; e.seq = txSequence++; diff --git a/ncpd/link.h b/ncpd/link.h index cf265c0..81732b6 100644 --- a/ncpd/link.h +++ b/ncpd/link.h @@ -28,6 +28,7 @@ #include #endif #include +#include #include "bufferstore.h" #include "bufferarray.h" @@ -151,6 +152,7 @@ private: void multiAck(struct timeval); void retransmit(); void transmitHoldQueue(int channel); + void transmitWaitQueue(); pthread_t checkthread; pthread_mutex_t queueMutex; @@ -168,6 +170,7 @@ private: vector ackWaitQueue; vector holdQueue; + vector waitQueue; bool xoff[256]; }; -- cgit v1.2.3