From d551b8badcb934f19f0abb1b5a74ece14d28c670 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 2 Apr 2020 15:04:29 +0200 Subject: [PATCH] cstp_send_file: fixed handling of syscall interrupts This also increases the buffer size. Signed-off-by: Nikos Mavrogiannopoulos --- src/tlslib.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/tlslib.c b/src/tlslib.c index b8f2d0d6..5264456c 100644 --- a/src/tlslib.c +++ b/src/tlslib.c @@ -115,17 +115,25 @@ ssize_t cstp_send(worker_st *ws, const void *data, ssize_t cstp_send_file(worker_st *ws, const char *file) { -int fd; -char buf[512]; -ssize_t len, total = 0; -int ret; + int fd; + char buf[1024]; + int counter = 100; /* allow 10 seconds for a full packet */ + ssize_t len, total = 0; + int ret; fd = open(file, O_RDONLY); if (fd == -1) return GNUTLS_E_FILE_ERROR; while ( (len = read( fd, buf, sizeof(buf))) > 0 || - (len == -1 && (errno == EINTR || errno == EAGAIN))) { + (len == -1 && counter > 0 && (errno == EINTR || errno == EAGAIN))) { + + if (len == -1) { + counter--; + ms_sleep(100); + continue; + } + ret = cstp_send(ws, buf, len); CSTP_FATAL_ERR(ws, ret);