diff options
author | Arran Cudbard-Bell <a.cudbardb@freeradius.org> | 2016-11-02 13:22:08 -0400 |
---|---|---|
committer | Arran Cudbard-Bell <a.cudbardb@freeradius.org> | 2016-11-02 13:22:24 -0400 |
commit | 5b0ad8bd851e4ce888b386be68c1821e4f2ca301 (patch) | |
tree | 48cebac7419594a6b26d7b5f8de8c4120a2ef0bc /src/stream.c | |
parent | fb88e6b78ea7fadd8eb0e07c6ecb2b1539874f97 (diff) |
Set SO_NOSIGPIPE on SCTP connections, for patforms which support it (macOS, FreeBSD etc...)
Change-Id: If4f2a99b2baf143551a7122f40ed1f9088c5936c
Signed-off-by: Arran Cudbard-Bell <a.cudbardb@freeradius.org>
Diffstat (limited to 'src/stream.c')
-rw-r--r-- | src/stream.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/stream.c b/src/stream.c index fd02b74..7d40df2 100644 --- a/src/stream.c +++ b/src/stream.c @@ -26,6 +26,14 @@ #include <netinet/sctp.h> #endif +/* + * Platforms that don't have MSG_NOSIGNAL (which disables SIGPIPE) + * usually have SO_NOSIGPIPE (set via setsockopt). + */ +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif + static int sctp_sock_activate_events(int fd) { #ifdef HAVE_LIBSCTP @@ -167,8 +175,16 @@ static int osmo_stream_cli_fd_cb(struct osmo_fd *ofd, unsigned int what) ofd->when &= ~BSC_FD_WRITE; LOGP(DLINP, LOGL_DEBUG, "connection done.\n"); cli->state = STREAM_CLI_STATE_CONNECTED; - if (cli->proto == IPPROTO_SCTP) + if (cli->proto == IPPROTO_SCTP) { +#ifdef SO_NOSIGPIPE + int val = 1; + + ret = setsockopt(ofd->fd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&val, sizeof(val)); + if (ret < 0) + LOGP(DLINP, LOGL_DEBUG, "Failed setting SO_NOSIGPIPE: %s\n", strerror(errno)); +#endif sctp_sock_activate_events(ofd->fd); + } if (cli->connect_cb) cli->connect_cb(cli); break; |