From b3c1d5d1dc0ebc2d4f323ebed072a322ef0e44ea Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 30 Oct 2022 13:07:08 +0000 Subject: [PATCH] stream: Use MSG_NOSIGNAL Without MSG_NOSIGNAL, sending to closed sockets will generate SIGPIPE. --- src/stream.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/stream.c b/src/stream.c index 153e2f1..fa34a2d 100644 --- a/src/stream.c +++ b/src/stream.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef ENABLE_TLS #include @@ -123,7 +124,11 @@ static int stream__flush_plain(struct stream* self) if (n_msgs == 0) return 0; - bytes_sent = writev(self->fd, iov, n_msgs); + struct msghdr msghdr = { + .msg_iov = iov, + .msg_iovlen = n_msgs, + }; + bytes_sent = sendmsg(self->fd, &msghdr, MSG_NOSIGNAL); if (bytes_sent < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { stream__poll_rw(self);