Fixed ReadFromRawPort(); it was severly broken (the missing B_RELATIVE_TIMEOUT

flag was reported by Bill Hayden).
I fixed only this method, and nothing else, but please have a look at how
I did it, and apply the same fixes, thanks!


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6902 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-03-05 01:49:48 +00:00
parent 7fb4c29b80
commit 3339a96ba6
+29 -36
View File
@@ -370,7 +370,7 @@ bool BLooper::IsMessageWaiting() const
int32 count; int32 count;
do do
{ {
count = port_buffer_size_etc(fMsgPort, B_TIMEOUT, 0); count = port_buffer_size_etc(fMsgPort, B_RELATIVE_TIMEOUT, 0);
} while (count == B_INTERRUPTED); } while (count == B_INTERRUPTED);
return count > 0; return count > 0;
@@ -1204,48 +1204,41 @@ DBG(OUT("LOOPER: _task0_() done: thread %ld\n", find_thread(NULL)));
return B_OK; return B_OK;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void* BLooper::ReadRawFromPort(int32* msgcode, bigtime_t tout)
void *
BLooper::ReadRawFromPort(int32 *msgCode, bigtime_t timeout)
{ {
DBG(OUT("BLooper::ReadRawFromPort()\n")); DBG(OUT("BLooper::ReadRawFromPort()\n"));
int8* msgbuffer = NULL; int8 *msgBuffer = NULL;
ssize_t buffersize; ssize_t bufferSize;
ssize_t bytesread;
if (tout == B_INFINITE_TIMEOUT) do {
{ bufferSize = port_buffer_size_etc(fMsgPort, B_RELATIVE_TIMEOUT, timeout);
buffersize = port_buffer_size(fMsgPort); } while (bufferSize == B_INTERRUPTED);
DBG(OUT("BLooper::ReadRawFromPort(): buffersize: %ld\n", buffersize));
} if (bufferSize < B_OK) {
else DBG(OUT("BLooper::ReadRawFromPort(): failed: %ld\n", bufferSize));
{ return NULL;
buffersize = port_buffer_size_etc(fMsgPort, 0, tout);
if (buffersize == B_TIMED_OUT || buffersize == B_BAD_PORT_ID ||
buffersize == B_WOULD_BLOCK)
{
DBG(OUT("BLooper::ReadRawFromPort() done 1\n"));
return NULL;
}
} }
if (buffersize > 0) if (bufferSize > 0)
msgbuffer = new int8[buffersize]; msgBuffer = new int8[bufferSize];
if (tout == B_INFINITE_TIMEOUT) // we don't want to wait again here, since that can only mean
{ // that someone else has read our message and our bufferSize
DBG(OUT("read_port()...\n")); // is now probably wrong
bytesread = read_port(fMsgPort, msgcode, msgbuffer, buffersize); DBG(OUT("read_port()...\n"));
DBG(OUT("read_port() done: %ld\n", bytesread)); bufferSize = read_port_etc(fMsgPort, msgCode, msgBuffer, bufferSize,
DBG(OUT("BLooper::ReadRawFromPort() read: %.4s\n", (char*)msgcode)); B_RELATIVE_TIMEOUT, 0);
if (bufferSize < B_OK) {
delete[] msgBuffer;
return NULL;
} }
else DBG(OUT("BLooper::ReadRawFromPort() read: %.4s\n", (char *)msgCode));
{ DBG(OUT("BLooper::ReadRawFromPort() done: %p\n", msgBuffer));
bytesread = read_port_etc(fMsgPort, msgcode, msgbuffer, buffersize, return msgBuffer;
B_TIMEOUT, tout);
}
DBG(OUT("BLooper::ReadRawFromPort() done: %p\n", msgbuffer));
return msgbuffer;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BMessage* BLooper::ReadMessageFromPort(bigtime_t tout) BMessage* BLooper::ReadMessageFromPort(bigtime_t tout)
{ {