Improved error handling on send data due to Apache proxy problems

This commit is contained in:
2014-12-26 12:18:04 +01:00
parent 27826ebb5b
commit b30cbd7740
+35 -10
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;
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;
}
/*-------------------------------------------------------------------*/