mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-26 06:32:44 +00:00
Fix compatibility with MSG_NOSIGNAL and Darwin
Darwin does not have MSG_NOSIGNAL but allows to set a SO_NOSIGPIPE option to disable sending SIGPIPE writing to closed socket. Note that *BSD has the SO_NOSIGPIPE option but does not affect all write calls so instead continue to use MSG_NOSIGNAL instead on that systems. Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
parent
2d971c6ec0
commit
ee4cf6a07c
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -146,4 +146,8 @@ SPICE_END_DECLS
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(SO_NOSIGPIPE) && defined(__APPLE__)
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
|
||||
#endif // RED_SYS_SOCKET_H_
|
||||
|
||||
Loading…
Reference in New Issue
Block a user