From 85e42c068c2a8c3e7b07e31b38bfd5d8f863c5bb Mon Sep 17 00:00:00 2001 From: jsorg71 Date: Sat, 5 Apr 2008 08:01:29 +0000 Subject: socket options fixes --- common/os_calls.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index 251e1f37..9b587c8d 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -260,18 +260,16 @@ g_tcp_set_no_delay(int sck) unsigned int option_len; #endif - option_value = 1; option_len = sizeof(option_value); - setsockopt(sck, IPPROTO_TCP, TCP_NODELAY, (char*)&option_value, - option_len); - if (getsockopt(sck, SOL_SOCKET, SO_SNDBUF, (char*)&option_value, + /* SOL_TCP IPPROTO_TCP */ + if (getsockopt(sck, IPPROTO_TCP, TCP_NODELAY, (char*)&option_value, &option_len) == 0) { - if (option_value < (1024 * 32)) + if (option_value == 0) { - option_value = 1024 * 32; + option_value = 1; option_len = sizeof(option_value); - setsockopt(sck, SOL_SOCKET, SO_SNDBUF, (char*)&option_value, + setsockopt(sck, IPPROTO_TCP, TCP_NODELAY, (char*)&option_value, option_len); } } @@ -299,14 +297,19 @@ g_tcp_socket(void) { return -1; } - option_value = 1; option_len = sizeof(option_value); - setsockopt(rv, IPPROTO_TCP, TCP_NODELAY, (char*)&option_value, - option_len); - option_value = 1; - setsockopt(rv, SOL_SOCKET, SO_REUSEADDR, (char*)&option_value, - option_len); - + if (getsockopt(rv, SOL_SOCKET, SO_REUSEADDR, (char*)&option_value, + &option_len) == 0) + { + if (option_value == 0) + { + option_value = 1; + option_len = sizeof(option_value); + setsockopt(rv, SOL_SOCKET, SO_REUSEADDR, (char*)&option_value, + option_len); + } + } + option_len = sizeof(option_value); if (getsockopt(rv, SOL_SOCKET, SO_SNDBUF, (char*)&option_value, &option_len) == 0) { -- cgit v1.2.1