Reputation: 21
For c send
function(blocking way) it's specified what function returns with size of sent bytes when it's received on destinations. I'm not sure that I understand all nuances, also after writing "demo" app with WSAIoctl
and WSARecv
on server side.
recv
call have read it fully?Upvotes: 0
Views: 753
Reputation: 724
Unless you are using a (somewhat exotic) library, a send
on a socket will return the number of bytes passed to the TCP buffer successfully, not the number of bytes received by the peer (see Microsoft´s docs for example).
When you are streaming data via a socket, you need to check the bytes effectively accepted into the TCP send buffer. That´s why usually a send command is inside a loop that will issue several send
s if needed.
Errors in send
are local: for example if the socket is closed by the peer during a sending operation (making your socket invalid) or if the operation times out (TCP buffer not emptying, i. e. peer not receiving data fast enough or some other trouble).
After all send
is completed you have no easy way of knowing if the peer received all the bytes you sent. You´ll usually just issue closesocket
and make sure that your socket has a proper linger option set (i. e. only close after timeout or sucessfully finishing the send). Alternatively you wait for a confirmation by the peer (for example via a recv
that returns zero bytes, indicating that the connection was gracefully closed).
Edit: typo
Upvotes: 1