From a75714ca455c728d34918dd12200fcec87ebc0d4 Mon Sep 17 00:00:00 2001 From: Haru Date: Sat, 24 Jan 2015 03:42:16 +0100 Subject: Fixed 18 minor issues Signed-off-by: Haru --- src/common/socket.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/common/socket.c') diff --git a/src/common/socket.c b/src/common/socket.c index 9fe08e6f1..1b7f36f8b 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -311,15 +311,18 @@ void setsocketopts(int fd, struct hSockOpt *opt) { // set SO_REAUSEADDR to true, unix only. on windows this option causes // the previous owner of the socket to give up, which is not desirable // in most cases, neither compatible with unix. - sSetsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof(yes)); + if (sSetsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof(yes))) + ShowWarning("setsocketopts: Unable to set SO_REUSEADDR mode for connection #%d!\n", fd); #ifdef SO_REUSEPORT - sSetsockopt(fd,SOL_SOCKET,SO_REUSEPORT,(char *)&yes,sizeof(yes)); -#endif -#endif + if (sSetsockopt(fd,SOL_SOCKET,SO_REUSEPORT,(char *)&yes,sizeof(yes))) + ShowWarning("setsocketopts: Unable to set SO_REUSEPORT mode for connection #%d!\n", fd); +#endif // SO_REUSEPORT +#endif // WIN32 // Set the socket into no-delay mode; otherwise packets get delayed for up to 200ms, likely creating server-side lag. // The RO protocol is mainly single-packet request/response, plus the FIFO model already does packet grouping anyway. - sSetsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&yes, sizeof(yes)); + if (sSetsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&yes, sizeof(yes))) + ShowWarning("setsocketopts: Unable to set TCP_NODELAY mode for connection #%d!\n", fd); if( opt && opt->setTimeo ) { struct timeval timeout; @@ -327,8 +330,10 @@ void setsocketopts(int fd, struct hSockOpt *opt) { timeout.tv_sec = 5; timeout.tv_usec = 0; - sSetsockopt(fd,SOL_SOCKET,SO_RCVTIMEO,(char *)&timeout,sizeof(timeout)); - sSetsockopt(fd,SOL_SOCKET,SO_SNDTIMEO,(char *)&timeout,sizeof(timeout)); + if (sSetsockopt(fd,SOL_SOCKET,SO_RCVTIMEO,(char *)&timeout,sizeof(timeout))) + ShowWarning("setsocketopts: Unable to set SO_RCVTIMEO for connection #%d!\n", fd); + if (sSetsockopt(fd,SOL_SOCKET,SO_SNDTIMEO,(char *)&timeout,sizeof(timeout))) + ShowWarning("setsocketopts: Unable to set SO_SNDTIMEO for connection #%d!\n", fd); } // force the socket into no-wait, graceful-close mode (should be the default, but better make sure) @@ -339,10 +344,12 @@ void setsocketopts(int fd, struct hSockOpt *opt) { ShowWarning("setsocketopts: Unable to set SO_LINGER mode for connection #%d!\n", fd); #ifdef TCP_THIN_LINEAR_TIMEOUTS - setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, &yes, sizeof yes); + if (sSetsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, (char *)&yes, sizeof(yes))) + ShowWarning("setsocketopts: Unable to set TCP_THIN_LINEAR_TIMEOUTS mode for connection #%d!\n", fd); #endif #ifdef TCP_THIN_DUPACK - setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof yes); + if (sSetsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, (char *)&yes, sizeof(yes))) + ShowWarning("setsocketopts: Unable to set TCP_THIN_DUPACK mode for connection #%d!\n", fd); #endif } @@ -1276,6 +1283,10 @@ int socket_getips(uint32* ips, int max) u_long ad; fd = sSocket(AF_INET, SOCK_STREAM, 0); + if (fd == -1) { + ShowError("socket_getips: Unable to create a socket!\n"); + return 0; + } memset(buf, 0x00, sizeof(buf)); -- cgit v1.2.3-70-g09d2