Skip to content

Commit

Permalink
lib: Implemented net_set_send_buffer_size() and net_set_recv_buffer_s…
Browse files Browse the repository at this point in the history
…ize().

These functions allow manipulating the kernel socket buffer sizes for a socket file descriptor.
  • Loading branch information
stephanbosch committed May 26, 2016
1 parent 1569b12 commit 8848174
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib/net.c
Expand Up @@ -351,6 +351,30 @@ int net_set_cork(int fd ATTR_UNUSED, bool cork ATTR_UNUSED)
#endif
}

int net_set_send_buffer_size(int fd, size_t size)
{
int opt;

if (size > INT_MAX) {
errno = EINVAL;
return -1;
}
opt = (int)size;
return setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &opt, sizeof(opt));
}

int net_set_recv_buffer_size(int fd, size_t size)
{
int opt;

if (size > INT_MAX) {
errno = EINVAL;
return -1;
}
opt = (int)size;
return setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt));
}

void net_get_ip_any4(struct ip_addr *ip)
{
ip->family = AF_INET;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/net.h
Expand Up @@ -80,6 +80,10 @@ void net_set_nonblock(int fd, bool nonblock);
Returns 0 if ok, -1 if failed. */
int net_set_cork(int fd, bool cork) ATTR_NOWARN_UNUSED_RESULT;

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

/* Set IP to contain INADDR_ANY for IPv4 or IPv6. The IPv6 any address may
include IPv4 depending on the system (Linux yes, BSD no). */
void net_get_ip_any4(struct ip_addr *ip);
Expand Down

0 comments on commit 8848174

Please sign in to comment.