Skip to main content
GameDev.net gamedev.net
🔒 Locked

Is data immediately sent?

Started by yct Nov 5, 2004 at 3:08 AM 5 replies 850+ views
Original Post
yct
yct
When I send data through TCP (using send()), is it guaranteed that the data is immediatly sent, or it may be sent only when the output buffer is full? If it's not sent immediately, how do I guarantee that it is sent immediately?
yct
yct
Thanx.

If I call send() with a blocking socket and it returns with a value equal to the size of the data sent, does it indicate that all data has been successfully sent, or merely that all data has been successfully put in the output buffer, and might be sent only later?
yct
yct
(in the last question i assume the TCP_NODELAY option isn't used)
markr
markr
When send() returns successfully the only thing that is guaranteed is that the system call has succeeded (i.e. data are buffered).

There are no guarantees that the data has been sent, or even will be sent.

The connection could die before the data get sent, in which case they will never arrive.

Mark
yct
yct
In this case, is there a way to check whether all data has been successfully sent, or wait till all data has been successfully sent?
beefsteak
beefsteak
I guess you "could" somehow figure the tcp stack by digging into some very low-level tcp system api. - However - I very much doubt that this will really help you.

The reason why data is not immediately sent is in order to increase efficiency. (The protocol overhead is minimized by grouping small, rapid messages and splitting long ones.) Therefore, attempting to force your system to execute send commands faster makes no sense. It is already trying to operate at maximum efficiency.

If you need to know wether a client has received something, best let the client send something back as acknowledgement. When you receive that acknowledgement bit on server-side, you know that the data got through.

Question: Why should one use acknowledgement when the protocol (tcp) already has acknowledgement implemented? Answer: Because the tcp protocol is taken care of by the system, in a seperate thread, asynchronous to your program. Trying to interfere with that, in your program, may eventually lead to a big mess.

If you really want and must avoid that redundancy, using the udp protocol instead of tcp is an option. With udp, the whole acknowledgement-thing is entirely in your hands and you are free to optimize it. OTOH, udp is by no means the holy grail, because it affords a lot of extra work and is much more prone to errors.


The output (send) buffer becoming full is an entirely different problem, which occurs only when a client's connection is either "too slow" or has become silently disconnected. You can recogize this has happened when the select command tells you the next send operation would block.


hope you find this useful,
cheers

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.