Let's say I have a sender application and a receiver application that communicate via UDP.
First, in the sender application, I send some data in two separate calls. First I send these 15 bytes:
[MYHEADER]hello
...then, immediately thereafter, I send another 15 bytes:
[MYHEADER]world
Now, in the receiver application, I'm listening on the same port with a UDP socket that's bound to the same address. Let's say that both messages have arrived (and in the same order) since the last time I checked the receiver socket.
Here's some pseudo-code that shows how I'm polling the socket for incoming data each frame:
uint32 PendingSize;
while (Socket->HasPendingData(PendingSize))
{
uint32 BytesRead;
uint8 MessageData[kMaxMessageSize];
if (Socket->Recv(MessageData, kMaxMessageSize, BytesRead))
{
// Do stuff here
// Will BytesRead be equal to PendingSize?
}
}
HasPendingData
wraps a call to ioctlsocket
with FIONREAD
, returning whether data is waiting in the receive buffer, and populating PendingSize
with the number of bytes waiting. Recv
calls recv
to read that data into a buffer that I can read. If it returns true, then I respond to the data I've received.
Here's my question. Which of these scenarios accurately reflects what would happen in this situation?
Option A.
HasPendingData
returns true and shows a pending size of 15 bytes.Recv
gives me the message[MYHEADER]hello
.HasPendingData
returns true and shows a pending size of 15 bytes.Recv
gives me the message[MYHEADER]world
.HasPendingData
returns false.
Option B.
HasPendingData
returns true and shows a pending size of 30 bytes.Recv
gives me the message[MYHEADER]hello[MYHEADER]world
.HasPendingData
returns false.
Any insight is appreciated. Thanks!