How do I use TCP_NODELAY?
Submitted by: AdministratorFirst off, be sure you really want to use it in the first place. It will disable the Nagle algorithm (see ``2.11 How can I force a socket to send the data in its buffer?''), which will cause network traffic to increase, with smaller than needed packets wasting bandwidth. Also, from what I have been able to tell, the speed increase is very small, so you should probably do it without TCP_NODELAY first, and only turn it on if there is a problem.
Here is a code example,
with a warning about using it
int flag = 1;
int result = setsockopt(sock,
/* socket affected */
IPPROTO_TCP,
/* set option at TCP level */
TCP_NODELAY,
/* name of option */
(char *) &flag,
/* the cast is historical cruft */
sizeof(int));
/* length of option value */
if (result < 0)
... handle the error ...
TCP_NODELAY is for a specific purpose; to disable the Nagle buffering algorithm. It should only be set for applications that send frequent small bursts of information without getting an immediate response, where timely delivery of data is required (the canonical example is mouse movements).
Submitted by: Administrator
Here is a code example,
with a warning about using it
int flag = 1;
int result = setsockopt(sock,
/* socket affected */
IPPROTO_TCP,
/* set option at TCP level */
TCP_NODELAY,
/* name of option */
(char *) &flag,
/* the cast is historical cruft */
sizeof(int));
/* length of option value */
if (result < 0)
... handle the error ...
TCP_NODELAY is for a specific purpose; to disable the Nagle buffering algorithm. It should only be set for applications that send frequent small bursts of information without getting an immediate response, where timely delivery of data is required (the canonical example is mouse movements).
Submitted by: Administrator
Read Online Unix Socket Programming Job Interview Questions And Answers
Top Unix Socket Programming Questions
☺ | How do Sockets Work? |
☺ | What is the difference between SO_REUSEADDR and SO_REUSEPORT? |
☺ | How would I put my socket in non-blocking mode? |
☺ | What exactly does SO_LINGER do? |
☺ | How can I be sure that UDP messages are received in order? |
Top Operating System (OS) Categories
☺ | RTOS Interview Questions. |
☺ | Windows 7 Interview Questions. |
☺ | MAC Operating System Interview Questions. |
☺ | Disk Operating System (DOS) Interview Questions. |
☺ | Shell Scripting Interview Questions. |