fix: use send instead of write to prevent SIGPIPE

blocking
Jef Roosens 2024-02-01 18:51:05 +01:00
parent a96ae39523
commit 64601b5f21
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 4 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/socket.h>
#include "lnm/loop.h" #include "lnm/loop.h"
#include "lnm/loop_internal.h" #include "lnm/loop_internal.h"
@ -43,7 +44,9 @@ void lnm_loop_conn_io_res(lnm_loop *l, lnm_loop_conn *conn) {
ssize_t res; ssize_t res;
do { do {
res = write(conn->fd, conn->w.buf, conn->w.size); // Send with MSG_NOSIGNAL prevents closed pipes from exiting the program
// with SIGPIPE
res = send(conn->fd, conn->w.buf, conn->w.size, MSG_NOSIGNAL);
} while (res < 0 && errno == EINTR); } while (res < 0 && errno == EINTR);
// Write can't be performed without blocking; we come back later // Write can't be performed without blocking; we come back later