flush send buffer on the background thread

This commit is contained in:
Benjamin Sergeant
2019-03-12 21:49:26 -07:00
parent 4de3ec995e
commit 11092027cd
4 changed files with 15 additions and 12 deletions

View File

@ -79,9 +79,8 @@ namespace ix
timeout.tv_sec = timeoutSecs;
timeout.tv_usec = 1000 * timeoutMs;
// int sockfd = _sockfd;
// int nfds = (std::max)(sockfd, _eventfd.getFd());
// Compute the highest fd.
// FIXME / cleanup
std::vector<int> fds = { _sockfd, _eventfd.getFd(), _fildes[0] };
int nfds = -1;
for (auto fd : fds)
@ -108,9 +107,6 @@ namespace ix
void Socket::wakeUpFromPoll()
{
// this will wake up the thread blocked on select, only needed on Linux
// _eventfd.notify();
uint64_t value = 0;
write(_fildes[1], &value, sizeof(value));
}

View File

@ -187,6 +187,10 @@ namespace ix
return;
}
// Make sure we send all the buffered data
// there can be a lot of it for large messages.
while (!isSendBufferEmpty() && !_requestInitCancellation) sendOnSocket();
while (true)
{
ssize_t ret = _socket->recv((char*)&_readbuf[0], _readbuf.size());
@ -586,11 +590,7 @@ namespace ix
}
}
// Make sure we send all the buffered data ; there can be a lot of it
// for large messages.
// TODO / this will block the sending thread ; we need to eval whether
// this is the right fix
while (!isSendBufferEmpty()) sendOnSocket();
_socket->wakeUpFromPoll();
return WebSocketSendInfo(true, compressionError, payloadSize, wireSize);
}