ReceiveFrom() can now return the message_port_info for the received

message, if desired.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25004 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-04-17 17:58:02 +00:00
parent 7727e08e5f
commit 2d9a40222f
2 changed files with 25 additions and 14 deletions
+2 -1
View File
@@ -132,7 +132,8 @@ public:
status_t SendReply(KMessage* message, KMessage* reply, status_t SendReply(KMessage* message, KMessage* reply,
bigtime_t deliveryTimeout = -1, bigtime_t replyTimeout = -1, bigtime_t deliveryTimeout = -1, bigtime_t replyTimeout = -1,
team_id senderTeam = -1); team_id senderTeam = -1);
status_t ReceiveFrom(port_id fromPort, bigtime_t timeout = -1); status_t ReceiveFrom(port_id fromPort, bigtime_t timeout = -1,
port_message_info* messageInfo = NULL);
void Dump(void (*printFunc)(const char*,...)); void Dump(void (*printFunc)(const char*,...));
+23 -13
View File
@@ -553,32 +553,43 @@ KMessage::SendReply(KMessage* message, KMessage* reply,
replyTimeout, senderTeam); replyTimeout, senderTeam);
} }
// ReceiveFrom // ReceiveFrom
status_t status_t
KMessage::ReceiveFrom(port_id fromPort, bigtime_t timeout) KMessage::ReceiveFrom(port_id fromPort, bigtime_t timeout,
port_message_info* messageInfo)
{ {
port_message_info _messageInfo;
if (messageInfo == NULL)
messageInfo = &_messageInfo;
// get the port buffer size // get the port buffer size
ssize_t size; status_t error;
if (timeout < 0) if (timeout < 0) {
size = port_buffer_size(fromPort); error = get_port_message_info_etc(fromPort, messageInfo, 0, 0);
else } else {
size = port_buffer_size_etc(fromPort, B_RELATIVE_TIMEOUT, timeout); error = get_port_message_info_etc(fromPort, messageInfo,
if (size < 0) B_RELATIVE_TIMEOUT, timeout);
return size; }
if (error != B_OK)
return error;
// allocate a buffer // allocate a buffer
uint8* buffer = (uint8*)malloc(size); uint8* buffer = (uint8*)malloc(messageInfo->size);
if (!buffer) if (!buffer)
return B_NO_MEMORY; return B_NO_MEMORY;
// read the message // read the message
int32 what; int32 what;
ssize_t realSize = read_port_etc(fromPort, &what, buffer, size, ssize_t realSize = read_port_etc(fromPort, &what, buffer, messageInfo->size,
B_RELATIVE_TIMEOUT, 0); B_RELATIVE_TIMEOUT, 0);
if (realSize < 0) if (realSize < 0)
return realSize; return realSize;
if (size != realSize) if (messageInfo->size != (size_t)realSize)
return B_ERROR; return B_ERROR;
// init the message // init the message
return SetTo(buffer, size, 0, return SetTo(buffer, messageInfo->size, 0,
KMESSAGE_OWNS_BUFFER | KMESSAGE_INIT_FROM_BUFFER); KMESSAGE_OWNS_BUFFER | KMESSAGE_INIT_FROM_BUFFER);
} }
@@ -600,7 +611,6 @@ KMessage::Dump(void (*printFunc)(const char*,...))
field.Name(), type, (char)(type >> 24), (char)(type >> 16), field.Name(), type, (char)(type >> 24), (char)(type >> 16),
(char)(type >> 8), (char)type, count, count == 1 ? "" : "s"); (char)(type >> 8), (char)type, count, count == 1 ? "" : "s");
} }
} }