diff options
author | Nikias Bassen | 2018-05-15 02:55:34 +0200 |
---|---|---|
committer | Nikias Bassen | 2018-05-15 02:55:34 +0200 |
commit | 149da9b53a7d16f6056337bfa0ed55f44466007a (patch) | |
tree | 365ee65a2404c4dd5efc5f6868b40494debd00be /common | |
parent | c724e70fb52ba45291dc73a2e369c0c5bae0ec2e (diff) | |
download | libusbmuxd-149da9b53a7d16f6056337bfa0ed55f44466007a.tar.gz libusbmuxd-149da9b53a7d16f6056337bfa0ed55f44466007a.tar.bz2 |
socket: Set socket options for usbmux connection to improve performance
Diffstat (limited to 'common')
-rw-r--r-- | common/socket.c | 23 |
1 files changed, 23 insertions, 0 deletions
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 <sys/socket.h> #include <sys/un.h> #include <netinet/in.h> +#include <netinet/tcp.h> #include <netdb.h> #include <arpa/inet.h> #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; |