HighCommander4
HighCommander4

Reputation: 52967

How can I explicitly wait for a TCP ACK before proceeding?

Is there a way to get send() to wait until all the data that has been sent has been ACK-ed (or return -1 if the timeout for an ACK has been reached), or is there some other mechanism to wait for the ACK after the send() but before doing something else?

I am using the standard Unix Berkeley sockets API.

I know I could implement an application-layer ACK, but I'd rather not do that when TCP's ACK serves the purpose perfectly well.

Upvotes: 13

Views: 8962

Answers (4)

TMtech
TMtech

Reputation: 1166

You can write a wrapper for send(). I have answered a question similar to this in another thread.

Upvotes: 1

Charles Lohr
Charles Lohr

Reputation: 919

I seem to have found a solution. At least on Linux, if you set SO_SNDBUF to a value of 0, it seems to wait for every transaction before allowing the next transfer through. While it will immediately return, it will not proceed to allowing another send to succeed until the previous send has sent. I haven't tried using select(...) to determine if the data has been sent.

This works on my Linux 3.8 kernel, and am confident it works elsewhere.

Upvotes: 2

valdo
valdo

Reputation: 12951

Unfortunately standard API doesn't reserve any appropriate way to do this. There could be a way to query the current TCP send window size/usage, but unfortunately it may not be queried by the standard means.

Of course there are tricky ways to achieve what you want. For instance on Windows one may create a network filter driver to monitor packet-level trafic.

Upvotes: 5

Karoly Horvath
Karoly Horvath

Reputation: 96366

AFAIK there is no way.

Also, it wouldn't be reliable, the ACK means only that the kernel received the data, in the meantime the client or its machine could have crashed. You would think the client received the data, but actually it never processed it.

Upvotes: 7

Related Questions