From: <sv...@ww...> - 2004-09-30 07:14:02
|
Author: mkrose Date: 2004-09-30 00:13:56 -0700 (Thu, 30 Sep 2004) New Revision: 1263 Modified: trunk/CSP/SimNet/NetworkInterface.cpp trunk/CSP/SimNet/NetworkInterface.h Log: Add a method to wait for incoming packets, but only if no incoming or outgoing packets are already queued. Useful for servers that are entirely event driven. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1263 Modified: trunk/CSP/SimNet/NetworkInterface.cpp =================================================================== --- trunk/CSP/SimNet/NetworkInterface.cpp 2004-09-30 07:11:41 UTC (rev 1262) +++ trunk/CSP/SimNet/NetworkInterface.cpp 2004-09-30 07:13:56 UTC (rev 1263) @@ -328,6 +328,15 @@ } +bool NetworkInterface::waitPending(double timeout) { + for (int queue_idx = 0; queue_idx <= 3; ++queue_idx) { + if (!m_RxQueues[queue_idx]->isEmpty()) return true; + if (!m_TxQueues[queue_idx]->isEmpty()) return true; + } + return (m_Socket->isPendingReceive(static_cast<int>(timeout * 1000))); +} + + static double DEBUG_recvtime; int NetworkInterface::receivePackets(double timeout) { @@ -350,7 +359,7 @@ watch.start(); while (true) { - + if (!m_Socket->isPendingReceive(0)) { watch.calibrate(); break; Modified: trunk/CSP/SimNet/NetworkInterface.h =================================================================== --- trunk/CSP/SimNet/NetworkInterface.h 2004-09-30 07:11:41 UTC (rev 1262) +++ trunk/CSP/SimNet/NetworkInterface.h 2004-09-30 07:13:56 UTC (rev 1263) @@ -138,6 +138,12 @@ void processIncoming(double timeout); void processOutgoing(double timeout); + /** Wait for incoming packets if all incoming and outgoing queues are empty. + * @param timeout the maximum time to wait, in seconds. + * @return false if the timeout expired (ie. no pending incoming packets and all queues empty). + */ + bool waitPending(double timeout); + void addPacketHandler(PacketHandler::Ref handler); void removePacketHandler(PacketHandler::Ref handler); |