From 149da9b53a7d16f6056337bfa0ed55f44466007a Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 15 May 2018 02:55:34 +0200 Subject: socket: Set socket options for usbmux connection to improve performance --- common/socket.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/common/socket.c b/common/socket.c index 4cdefd6..30b2b8c 100644 --- a/common/socket.c +++ b/common/socket.c @@ -35,6 +35,7 @@ static int wsa_init = 0; #include #include #include +#include #include #include #endif @@ -116,6 +117,7 @@ int socket_connect_unix(const char *filename) #ifdef SO_NOSIGPIPE int yes = 1; #endif + int bufsize = 0x20000; // check if socket file exists... if (stat(filename, &fst) != 0) { @@ -138,6 +140,14 @@ int socket_connect_unix(const char *filename) return -1; } + if (setsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(int)) == -1) { + perror("Could not set send buffer for socket"); + } + + if (setsockopt(sfd, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(int)) == -1) { + perror("Could not set receive buffer for socket"); + } + #ifdef SO_NOSIGPIPE if (setsockopt(sfd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&yes, sizeof(int)) == -1) { perror("setsockopt()"); @@ -225,6 +235,7 @@ int socket_connect(const char *addr, uint16_t port) { int sfd = -1; int yes = 1; + int bufsize = 0x20000; struct hostent *hp; struct sockaddr_in saddr; #ifdef WIN32 @@ -275,6 +286,18 @@ int socket_connect(const char *addr, uint16_t port) } #endif + if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, (void*)&yes, sizeof(int)) == -1) { + perror("Could not set TCP_NODELAY on socket"); + } + + if (setsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(int)) == -1) { + perror("Could not set send buffer for socket"); + } + + if (setsockopt(sfd, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(int)) == -1) { + perror("Could not set receive buffer for socket"); + } + memset((void *) &saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = *(uint32_t *) hp->h_addr; -- cgit v1.1-32-gdbae