socket: Set socket options for usbmux connection to improve performance
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 @@
 #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 @@
 #ifdef SO_NOSIGPIPE
 	int yes = 1;
 #endif
+	int bufsize = 0x20000;
 
 	// check if socket file exists...
 	if (stat(filename, &fst) != 0) {
@@ -138,6 +140,14 @@
 		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 sfd = -1;
 	int yes = 1;
+	int bufsize = 0x20000;
 	struct hostent *hp;
 	struct sockaddr_in saddr;
 #ifdef WIN32
@@ -275,6 +286,18 @@
 	}
 #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;