From 78d28fd6e50b0d0029be4b63ba1711ad04af0982 Mon Sep 17 00:00:00 2001 From: crs Date: Wed, 26 Jun 2002 13:31:06 +0000 Subject: [PATCH] fixed getSize() to be non-blocking in CInputPacketStream. --- synergy/CInputPacketStream.cpp | 50 ++++++++++++++++++++++++++-------- synergy/CInputPacketStream.h | 2 ++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/synergy/CInputPacketStream.cpp b/synergy/CInputPacketStream.cpp index 76c03620..c29a6a04 100644 --- a/synergy/CInputPacketStream.cpp +++ b/synergy/CInputPacketStream.cpp @@ -32,7 +32,7 @@ CInputPacketStream::read(void* buffer, UInt32 n) // wait for entire message to be read. return immediately if // stream hungup. - if (getSizeNoLock() == 0) { + if (!waitForFullMessage()) { return 0; } @@ -60,24 +60,50 @@ CInputPacketStream::getSize() const UInt32 CInputPacketStream::getSizeNoLock() const { - while (!hasFullMessage()) { + while (!hasFullMessage() && getStream()->getSize() > 0) { // read more data - char buffer[4096]; - UInt32 n = getStream()->read(buffer, sizeof(buffer)); - - // return if stream hungup - if (n == 0) { - m_buffer.hangup(); - return 0; + if (!getMoreMessage()) { + // stream hungup + return false; } - - // append to our buffer - m_buffer.write(buffer, n); } return m_size; } +bool +CInputPacketStream::waitForFullMessage() const +{ + while (!hasFullMessage()) { + // read more data + if (!getMoreMessage()) { + // stream hungup + return false; + } + } + + return true; +} + +bool +CInputPacketStream::getMoreMessage() const +{ + // read more data + char buffer[4096]; + UInt32 n = getStream()->read(buffer, sizeof(buffer)); + + // return if stream hungup + if (n == 0) { + m_buffer.hangup(); + return false; + } + + // append to our buffer + m_buffer.write(buffer, n); + + return true; +} + bool CInputPacketStream::hasFullMessage() const { diff --git a/synergy/CInputPacketStream.h b/synergy/CInputPacketStream.h index 11d41703..03fd32be 100644 --- a/synergy/CInputPacketStream.h +++ b/synergy/CInputPacketStream.h @@ -21,6 +21,8 @@ public: private: UInt32 getSizeNoLock() const; + bool waitForFullMessage() const; + bool getMoreMessage() const; bool hasFullMessage() const; private: