setsockopt SO_NOSIGPIPE when nessary
parent
51c9b28f90
commit
39a6e7b656
|
|
@ -871,6 +871,16 @@ int socketBind(int sock, const char *bind_ipaddr, const int port)
|
||||||
return 0;
|
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 socketServer(const char *bind_ipaddr, const int port, int *err_no)
|
||||||
{
|
{
|
||||||
int sock;
|
int sock;
|
||||||
|
|
@ -886,6 +896,8 @@ int socketServer(const char *bind_ipaddr, const int port, int *err_no)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SET_SOCKOPT_NOSIGPIPE(sock);
|
||||||
|
|
||||||
result = 1;
|
result = 1;
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &result, sizeof(int))<0)
|
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 linger linger;
|
||||||
struct timeval waittime;
|
struct timeval waittime;
|
||||||
|
|
||||||
|
SET_SOCKOPT_NOSIGPIPE(fd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
linger.l_onoff = 1;
|
linger.l_onoff = 1;
|
||||||
#ifdef OS_FREEBSD
|
#ifdef OS_FREEBSD
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue