Reputation: 381
I'm using send on Linux std socket to write a packet over network. Send call, buffers data and "always" return values greater than 0. Send Pass the problem to the operating system and the lower level. How can i stop the send call and wait for the delivery of the packet to the other endsystem? Waiting for the TCP ACK or something like that?
if (send(broker->socket, packet, sizeof(packet), 0) < sizeof(packet)){
return -3;
}
The test will like:
start to send packet,remove the ethernet,reattach.
Thanks, sorry for my bad english.
Upvotes: 0
Views: 99
Reputation: 182684
There's no real robust way to find out if the remote peer acked your data. In fact, even if the remote TCP acks your data that doesn't mean the remote process read it. The simplest method is to implement a sort of application-layer ACK where the peer sends back a byte signaling "ok, got it".
send
and it returns almost immediatelyrecv
which blocksrecv
unblocksAt this point you can be certain the remote side received your data.
Upvotes: 1