http: Add timeout on no response.

Firewalls can cause this, by opening a connection but never responding.
This commit is contained in:
Unknown W. Brackets committed 2018-12-27 10:15:58 -08:00
1 parent 2dbdd73e5f
commit 359afb2d6b
5 files changed
+25 -8

No files matched your search

+6 -2
View File
@@ -146,8 +146,12 @@ bool Buffer::FlushToFile(const char *filename) {
return true;
}
bool Buffer::FlushSocket(uintptr_t sock) {
bool Buffer::FlushSocket(uintptr_t sock, double timeout) {
for (size_t pos = 0, end = data_.size(); pos < end; ) {
if (timeout >= 0.0 && !fd_util::WaitUntilReady(sock, timeout, true)) {
ELOG("FlushSocket timed out");
return false;
}
int sent = send(sock, &data_[pos], (int)(end - pos), MSG_NOSIGNAL);
if (sent < 0) {
ELOG("FlushSocket failed");
@@ -156,7 +160,7 @@ bool Buffer::FlushSocket(uintptr_t sock) {
pos += sent;
// Buffer full, don't spin.
if (sent == 0) {
if (sent == 0 && timeout < 0.0) {
sleep_ms(1);
}
}