mirror of
https://gitea.psi.ch/ELOG/elog.git
synced 2026-09-08 17:13:56 +00:00
Improved error handling on send data due to Apache proxy problems
This commit is contained in:
parent
27826ebb5b
commit
b30cbd7740
43
src/elogd.c
43
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;
|
time_t start, now;
|
||||||
|
char *pbuf;
|
||||||
|
|
||||||
time(&start);
|
time(&start);
|
||||||
|
sent = 0;
|
||||||
|
send_size = buf_size;
|
||||||
|
pbuf = buf;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
if (send_size > 65536)
|
||||||
|
send_packet = 65536;
|
||||||
|
else
|
||||||
|
send_packet = send_size;
|
||||||
|
|
||||||
#ifdef HAVE_SSL
|
#ifdef HAVE_SSL
|
||||||
SSL *ssl = (SSL *)p;
|
SSL *ssl = (SSL *)p;
|
||||||
if (ssl)
|
if (ssl)
|
||||||
status = SSL_write(ssl, buf, size);
|
status = SSL_write(ssl, pbuf, send_packet);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
status = send(sock, buf, size, 0);
|
status = send(sock, pbuf, send_packet, 0);
|
||||||
|
|
||||||
|
// abort after 30 seconds
|
||||||
time(&now);
|
time(&now);
|
||||||
|
if (now > start+30) {
|
||||||
// abort after 10 seconds
|
printf("Timeout after 30 seconds\n");
|
||||||
if (now > start+10)
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// repeat if we were interrupted by alarm() signal
|
// repeat if we were interrupted by alarm() signal
|
||||||
} while (status == -1 && errno == EINTR);
|
if (status == -1 && errno == EINTR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
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 sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user