From 1acf98ef54b1a2f2e489a601a631d5e4e5b4672d Mon Sep 17 00:00:00 2001 From: Mid <> Date: Tue, 15 Apr 2025 12:07:27 +0300 Subject: [PATCH] Avoid SIGPIPE --- main2.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main2.c b/main2.c index 98ec389..fe1ccc6 100644 --- a/main2.c +++ b/main2.c @@ -101,15 +101,18 @@ static void consume(Client *cli, size_t n) { cli->len -= n; } -static void transmit(Client *cli, const char *buf, size_t sz) { +static int transmit(Client *cli, const char *buf, size_t sz) { while(sz) { - ssize_t s = send(cli->fd, buf, sz, 0); + ssize_t s = send(cli->fd, buf, sz, MSG_NOSIGNAL); if(s >= 0) { buf += s; sz -= s; + } else { + return 0; } } + return 1; } static void transmit_all(const char *buf, size_t sz) { @@ -306,7 +309,9 @@ static int handle(Client *cli) { size_t rsize = cli->len; int pret = phr_decode_chunked(&cli->chudec, cli->buf, &rsize); - if(pret == -1) return 0; + if(pret == -1) { + return 0; + } stream_step(cli->buf, rsize);