stream: Use MSG_NOSIGNAL

Without MSG_NOSIGNAL, sending to closed sockets will generate SIGPIPE.
pull/80/head
Andri Yngvason 2022-10-30 13:07:08 +00:00
parent 95742676c9
commit b3c1d5d1dc
1 changed files with 6 additions and 1 deletions

View File

@ -25,6 +25,7 @@
#include <aml.h> #include <aml.h>
#include <fcntl.h> #include <fcntl.h>
#include <poll.h> #include <poll.h>
#include <sys/socket.h>
#ifdef ENABLE_TLS #ifdef ENABLE_TLS
#include <gnutls/gnutls.h> #include <gnutls/gnutls.h>
@ -123,7 +124,11 @@ static int stream__flush_plain(struct stream* self)
if (n_msgs == 0) if (n_msgs == 0)
return 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 (bytes_sent < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) { if (errno == EAGAIN || errno == EWOULDBLOCK) {
stream__poll_rw(self); stream__poll_rw(self);