diff options
author | Andy Richards <[email protected]> | 2012-10-08 11:16:54 +0100 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2012-10-08 14:29:00 +0200 |
commit | 292fd914db1cebcd4ed6589b26df3f1e3faf623b (patch) | |
tree | 68d9bebef72b9a0d7b467d41c8bcbc1bef2b67a2 /lib/odbc/c_src/odbcserver.c | |
parent | aead007ef22abb50d8cfbd0a58eb9f41fbb2f363 (diff) | |
download | otp-292fd914db1cebcd4ed6589b26df3f1e3faf623b.tar.gz otp-292fd914db1cebcd4ed6589b26df3f1e3faf623b.tar.bz2 otp-292fd914db1cebcd4ed6589b26df3f1e3faf623b.zip |
Under Unix enable TCP_NODELAY to disable Nagel's socket algorithm
Under Unix enable TCP_NODELAY to disable Nagel's socket algorithm
(Removes ~40ms delay on Redhat ES 6).
Diffstat (limited to 'lib/odbc/c_src/odbcserver.c')
-rw-r--r-- | lib/odbc/c_src/odbcserver.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/odbc/c_src/odbcserver.c b/lib/odbc/c_src/odbcserver.c index 6d4460014f..fe81d1dd3a 100644 --- a/lib/odbc/c_src/odbcserver.c +++ b/lib/odbc/c_src/odbcserver.c @@ -104,6 +104,7 @@ #ifdef UNIX #include <unistd.h> +#include <netinet/tcp.h> #endif #if defined WIN32 @@ -201,6 +202,7 @@ static byte *receive_msg(int socket); static Boolean receive_msg_part(int socket, byte * buffer, size_t msg_len); static Boolean send_msg_part(int socket, byte * buffer, size_t msg_len); static void close_socket(int socket); +static void tcp_nodelay(int sock); #endif static void clean_socket_lib(void); @@ -1782,6 +1784,10 @@ static int connect_to_erlang(const char *port) sin6.sin6_addr = in6addr_loopback; if (connect(sock, (struct sockaddr*)&sin6, sizeof(sin6)) == 0) { + /* Enable TCP_NODELAY to disable Nagel's socket algorithm. (Removes ~40ms delay on Redhat ES 6). */ + #ifdef UNIX + tcp_nodelay(sock); + #endif return sock; } close_socket(sock); @@ -1797,9 +1803,24 @@ static int connect_to_erlang(const char *port) close_socket(sock); DO_EXIT(EXIT_SOCKET_CONNECT); } + + /* Enable TCP_NODELAY to disable Nagel's socket algorithm. (Removes ~40ms delay on Redhat ES 6). */ + #ifdef UNIX + tcp_nodelay(sock); + #endif return sock; } +#ifdef UNIX +static void tcp_nodelay(int sock) +{ + int flag = 1; + int result = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)); + if (result < 0) { + DO_EXIT(EXIT_SOCKET_CONNECT); + } +} +#endif #ifdef WIN32 static void close_socket(SOCKET socket) { |