diff --git a/server/net-utils.c b/server/net-utils.c index 144bfd8f..78b94886 100644 --- a/server/net-utils.c +++ b/server/net-utils.c @@ -150,3 +150,15 @@ int red_socket_get_no_delay(int fd) return delay_val; } + +/** + * red_socket_set_nosigpipe + * @fd: a socket file descriptor + */ +void red_socket_set_nosigpipe(int fd, bool enable) +{ +#if defined(SO_NOSIGPIPE) && defined(__APPLE__) + int val = !!enable; + setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (const void *) &val, sizeof(val)); +#endif +} diff --git a/server/net-utils.h b/server/net-utils.h index 5b8c9163..62ff2f23 100644 --- a/server/net-utils.h +++ b/server/net-utils.h @@ -27,6 +27,7 @@ bool red_socket_set_keepalive(int fd, bool enable, int timeout); bool red_socket_set_no_delay(int fd, bool no_delay); int red_socket_get_no_delay(int fd); bool red_socket_set_non_blocking(int fd, bool non_blocking); +void red_socket_set_nosigpipe(int fd, bool enable); SPICE_END_DECLS diff --git a/server/reds.cpp b/server/reds.cpp index 23c17f3d..fb6e7795 100644 --- a/server/reds.cpp +++ b/server/reds.cpp @@ -2401,6 +2401,7 @@ static RedLinkInfo *reds_init_client_connection(RedsState *reds, int socket) } red_socket_set_keepalive(socket, TRUE, KEEPALIVE_TIMEOUT); + red_socket_set_nosigpipe(socket, true); link = g_new0(RedLinkInfo, 1); link->reds = reds; diff --git a/server/sys-socket.h b/server/sys-socket.h index b13ecdee..f8916a2f 100644 --- a/server/sys-socket.h +++ b/server/sys-socket.h @@ -146,4 +146,8 @@ SPICE_END_DECLS #endif +#if defined(SO_NOSIGPIPE) && defined(__APPLE__) +#define MSG_NOSIGNAL 0 +#endif + #endif // RED_SYS_SOCKET_H_