setsockopt SO_NOSIGPIPE when nessary

pull/10/head
yuqing 2016-08-12 17:09:18 +08:00
parent 51c9b28f90
commit 39a6e7b656
1 changed files with 14 additions and 0 deletions

View File

@ -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