Skip to content

Commit

Permalink
lib: Created net_set_tcp_nodelay(), which enables the TCP_NODELAY soc…
Browse files Browse the repository at this point in the history
…ket option.

This disables the TCP Nagle algorithm.
  • Loading branch information
stephanbosch committed Jun 16, 2016
1 parent 095481f commit 2dca65b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/net.c
Expand Up @@ -351,6 +351,13 @@ int net_set_cork(int fd ATTR_UNUSED, bool cork ATTR_UNUSED)
#endif
}

int net_set_tcp_nodelay(int fd, bool nodelay)
{
int val = nodelay;

return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
}

int net_set_send_buffer_size(int fd, size_t size)
{
int opt;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/net.h
Expand Up @@ -87,6 +87,8 @@ void net_set_nonblock(int fd, bool nonblock);
/* Set TCP_CORK if supported, ie. don't send out partial frames.
Returns 0 if ok, -1 if failed. */
int net_set_cork(int fd, bool cork) ATTR_NOWARN_UNUSED_RESULT;
/* Set TCP_NODELAY, which disables the Nagle algorithm. */
int net_set_tcp_nodelay(int fd, bool nodelay);

/* Set socket kernel buffer sizes */
int net_set_send_buffer_size(int fd, size_t size);
Expand Down

0 comments on commit 2dca65b

Please sign in to comment.