fixed getSize() to be non-blocking in CInputPacketStream.

This commit is contained in:
crs 2002-06-26 13:31:06 +00:00
parent 6cc3b50d3b
commit 78d28fd6e5
2 changed files with 40 additions and 12 deletions

View File

@ -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;
}
@ -59,8 +59,35 @@ CInputPacketStream::getSize() const
UInt32
CInputPacketStream::getSizeNoLock() const
{
while (!hasFullMessage() && getStream()->getSize() > 0) {
// read more data
if (!getMoreMessage()) {
// stream hungup
return false;
}
}
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));
@ -68,14 +95,13 @@ CInputPacketStream::getSizeNoLock() const
// return if stream hungup
if (n == 0) {
m_buffer.hangup();
return 0;
return false;
}
// append to our buffer
m_buffer.write(buffer, n);
}
return m_size;
return true;
}
bool

View File

@ -21,6 +21,8 @@ public:
private:
UInt32 getSizeNoLock() const;
bool waitForFullMessage() const;
bool getMoreMessage() const;
bool hasFullMessage() const;
private: