Improved error handling on send data due to Apache proxy problems

This commit is contained in:
Stefan Ritt 2014-12-26 12:18:04 +01:00
parent 27826ebb5b
commit b30cbd7740

View File

@ -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);
time(&now);
// abort after 10 seconds // abort after 30 seconds
if (now > start+10) time(&now);
if (now > start+30) {
printf("Timeout after 30 seconds\n");
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;
}
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;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/