Daniel Trugman
Daniel Trugman

Reputation: 8491

Does WSASend send all WSABUF buffers as a single packet?

The title probably explains itself best.

Anyway, I have a data buffer received from an another source, and I want to send it in a single UDP packet that contains a sequence number (as the first byte) -> I want to add the sequence number to the given buffer!

Instead of allocating a new buffer, settings it's size to size+4, setting the sequence number as the first byte and copying the data into the buffer, I would like to just use the scatter gather mechanism of WSA.

Sadly though, no WSA document specifies explicitly that WSASend guarantees that all buffer will be sent a single packet (The packet size will be held as < 1500 bytes).

Can I be certain that it will work that way? Or should I re-build the packet?

Best, Daniel

Upvotes: 4

Views: 911

Answers (1)

Hans Passant
Hans Passant

Reputation: 941217

It is documented in a round-about way:

For message-oriented sockets, do not exceed the maximum message size of the underlying provider, which can be obtained by getting the value of socket option SO_MAX_MSG_SIZE. If the data is too long to pass atomically through the underlying protocol the error WSAEMSGSIZE is returned, and no data is transmitted.

So clearly it combines the data from the buffers to make a single UDP packet. If it didn't then there would no point in returning the WSAEMSGSIZE error.

Upvotes: 2

Related Questions