tlsgate

TLS reverse proxy
git clone git://git.akobets.xyz/tlsgate
Log | Files | Refs | README | LICENSE

commit 23ef591e4b8b6801809d8b44f381b7b938707d43
parent 2bf091f0d917f4a6e380ba8cbf9225d2f3637144
Author: Artem Kobets <artem@akobets.xyz>
Date:   Thu,  3 Sep 2020 14:25:06 +0300

EINTR handling

Diffstat:
Mserve.c | 15++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/serve.c b/serve.c @@ -1,3 +1,4 @@ +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> @@ -17,6 +18,7 @@ void serve(struct tls *ctx, int fd) { pid_t pid; + pid = fork(); if (pid == -1) { warn("fork"); @@ -33,7 +35,9 @@ serve(struct tls *ctx, int fd) ssize_t nread; nread = read(fd, buf, sizeof(buf)); - if (nread == -1 || nread == 0) + if (nread == -1 && errno != EINTR) + break; + if (nread == 0) break; if (full_tls_write(ctx, buf, nread) == -1) @@ -59,7 +63,9 @@ serve(struct tls *ctx, int fd) break; } } - if (nread == -1 || nread == 0) + if (nread == -1) + break; + if (nread == 0) break; if (full_write(fd, buf, nread) == -1) @@ -97,7 +103,10 @@ full_write(int fd, char *buf, ssize_t len) while (len > 0) { nwritten = write(fd, buf, len); if (nwritten == -1) { - return -1; + if (errno == EINTR) + continue; + else + return -1; } else { len -= nwritten; buf += nwritten;