From 39a6e7b656262ddf5c894fb020cee959fc3b8556 Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 12 Aug 2016 17:09:18 +0800 Subject: [PATCH] setsockopt SO_NOSIGPIPE when nessary --- src/sockopt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/sockopt.c b/src/sockopt.c index cd226ca..671f71f 100644 --- a/src/sockopt.c +++ b/src/sockopt.c @@ -871,6 +871,16 @@ int socketBind(int sock, const char *bind_ipaddr, const int port) return 0; } +#ifdef SO_NOSIGPIPE +#define SET_SOCKOPT_NOSIGPIPE(sock) \ + do { \ + int set = 1; \ + setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof(int)); \ + } while (0) +#else +#define SET_SOCKOPT_NOSIGPIPE(sock) +#endif + int socketServer(const char *bind_ipaddr, const int port, int *err_no) { int sock; @@ -886,6 +896,8 @@ int socketServer(const char *bind_ipaddr, const int port, int *err_no) return -1; } + SET_SOCKOPT_NOSIGPIPE(sock); + result = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &result, sizeof(int))<0) { @@ -1428,6 +1440,8 @@ int tcpsetserveropt(int fd, const int timeout) struct linger linger; struct timeval waittime; + SET_SOCKOPT_NOSIGPIPE(fd); + /* linger.l_onoff = 1; #ifdef OS_FREEBSD