From b30cbd7740cd99dba8516a4143bb4f1827e25849 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Fri, 26 Dec 2014 12:18:04 +0100 Subject: [PATCH] Improved error handling on send data due to Apache proxy problems --- src/elogd.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/elogd.c b/src/elogd.c index 3b4c1665..cc1a5b05 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -1768,32 +1768,57 @@ int setuser(char *str) /*-------------------------------------------------------------------*/ -int send_with_timeout(void *p, int sock, char *buf, int size) +int send_with_timeout(void *p, int sock, char *buf, int buf_size) { - int status; + int status, sent, send_size, send_packet; time_t start, now; + char *pbuf; time(&start); + sent = 0; + send_size = buf_size; + pbuf = buf; do { + if (send_size > 65536) + send_packet = 65536; + else + send_packet = send_size; + #ifdef HAVE_SSL SSL *ssl = (SSL *)p; if (ssl) - status = SSL_write(ssl, buf, size); + status = SSL_write(ssl, pbuf, send_packet); else #endif - status = send(sock, buf, size, 0); - - time(&now); + status = send(sock, pbuf, send_packet, 0); - // abort after 10 seconds - if (now > start+10) + // abort after 30 seconds + time(&now); + if (now > start+30) { + printf("Timeout after 30 seconds\n"); break; + } // repeat if we were interrupted by alarm() signal - } while (status == -1 && errno == EINTR); + if (status == -1 && errno == EINTR) { + continue; + } + + if (status == -1) + break; + + if (status > 0) + sent += status; + + if (status > 0 && sent < buf_size) { + pbuf += status; + send_size -= status; + } + + } while (sent < buf_size); - return 0; + return sent; } /*-------------------------------------------------------------------*/