4

I would like a precision with WSARecv.

Basically it seems you can use the function with an array of WSABUFs.

1- In an overlapped I/O context WITHOUT completion ports, say I use WSARecv() on a datagram socket with an array of 48 WSABUFs, does it means I can receive 48 different UDP packets (1 packet for each buffer) in a single call (say they arrive at the same exact moment)? Or is the only way to receive the 48 packets is to use WSARecv() 48 times after the event has been signaled (using overlapped I/O with events but not completion ports, I repeat).

2- In a context WITH I/O completion ports/overlapped I/O, does it means I can replace this

int n = 48;
for (int i = 0; i < n; i++)
   WSARecv(sock, &buffer_array[i], 1, NULL, 0, &overlapped, completion_routine);

With this?

WSARecv(sock, buffer_array, 48, NULL, 0, &overlapped, completion_routine);

Basically does it mean's calling WSARecv() with 48 buffers will post 48 read requests?

3- If not, what is the purpose of an array of WSABUF's? I mean, only one of correct size suffice no?

Thanks a lot!

Yannick
  • 830
  • 7
  • 27
  • 1
    `what is the purpose of an array of WSABUF's?` Some explanations from Microsoft: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740138%28v=vs.85%29.aspx Scatter/Gather I/O – Alex F Jun 04 '15 at 09:38
  • Yes, I read that page before but due to my newbishness in network programming I didn't understand very well whats scatter/gather I/O – Yannick Jun 04 '15 at 20:50

1 Answers1

6

One WSARecv() == one datagram. Multiple buffers allow you to split that datagram up into a header, body, trailer, etc., if you know how big those things are in advance. It doesn't let you receive 48 datagrams at once.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I see, so that's basically to divide the packet into logical parts at once when possible? Answer accepted – Yannick Jun 04 '15 at 20:51