@@ -35,6 +35,7 @@ static int wsa_init = 0;
3535#include <sys/socket.h>
3636#include <sys/un.h>
3737#include <netinet/in.h>
38+ #include <netinet/tcp.h>
3839#include <netdb.h>
3940#include <arpa/inet.h>
4041#endif
@@ -116,6 +117,7 @@ int socket_connect_unix(const char *filename)
116117#ifdef SO_NOSIGPIPE
117118 int yes = 1 ;
118119#endif
120+ int bufsize = 0x20000 ;
119121
120122 // check if socket file exists...
121123 if (stat (filename , & fst ) != 0 ) {
@@ -138,6 +140,14 @@ int socket_connect_unix(const char *filename)
138140 return -1 ;
139141 }
140142
143+ if (setsockopt (sfd , SOL_SOCKET , SO_SNDBUF , & bufsize , sizeof (int )) == -1 ) {
144+ perror ("Could not set send buffer for socket" );
145+ }
146+
147+ if (setsockopt (sfd , SOL_SOCKET , SO_RCVBUF , & bufsize , sizeof (int )) == -1 ) {
148+ perror ("Could not set receive buffer for socket" );
149+ }
150+
141151#ifdef SO_NOSIGPIPE
142152 if (setsockopt (sfd , SOL_SOCKET , SO_NOSIGPIPE , (void * )& yes , sizeof (int )) == -1 ) {
143153 perror ("setsockopt()" );
@@ -225,6 +235,7 @@ int socket_connect(const char *addr, uint16_t port)
225235{
226236 int sfd = -1 ;
227237 int yes = 1 ;
238+ int bufsize = 0x20000 ;
228239 struct hostent * hp ;
229240 struct sockaddr_in saddr ;
230241#ifdef WIN32
@@ -275,6 +286,18 @@ int socket_connect(const char *addr, uint16_t port)
275286 }
276287#endif
277288
289+ if (setsockopt (sfd , IPPROTO_TCP , TCP_NODELAY , (void * )& yes , sizeof (int )) == -1 ) {
290+ perror ("Could not set TCP_NODELAY on socket" );
291+ }
292+
293+ if (setsockopt (sfd , SOL_SOCKET , SO_SNDBUF , & bufsize , sizeof (int )) == -1 ) {
294+ perror ("Could not set send buffer for socket" );
295+ }
296+
297+ if (setsockopt (sfd , SOL_SOCKET , SO_RCVBUF , & bufsize , sizeof (int )) == -1 ) {
298+ perror ("Could not set receive buffer for socket" );
299+ }
300+
278301 memset ((void * ) & saddr , 0 , sizeof (saddr ));
279302 saddr .sin_family = AF_INET ;
280303 saddr .sin_addr .s_addr = * (uint32_t * ) hp -> h_addr ;
0 commit comments