flush send buffer on the background thread
This commit is contained in:
parent
4de3ec995e
commit
11092027cd
@ -79,9 +79,8 @@ namespace ix
|
|||||||
timeout.tv_sec = timeoutSecs;
|
timeout.tv_sec = timeoutSecs;
|
||||||
timeout.tv_usec = 1000 * timeoutMs;
|
timeout.tv_usec = 1000 * timeoutMs;
|
||||||
|
|
||||||
// int sockfd = _sockfd;
|
// Compute the highest fd.
|
||||||
// int nfds = (std::max)(sockfd, _eventfd.getFd());
|
// FIXME / cleanup
|
||||||
|
|
||||||
std::vector<int> fds = { _sockfd, _eventfd.getFd(), _fildes[0] };
|
std::vector<int> fds = { _sockfd, _eventfd.getFd(), _fildes[0] };
|
||||||
int nfds = -1;
|
int nfds = -1;
|
||||||
for (auto fd : fds)
|
for (auto fd : fds)
|
||||||
@ -108,9 +107,6 @@ namespace ix
|
|||||||
|
|
||||||
void Socket::wakeUpFromPoll()
|
void Socket::wakeUpFromPoll()
|
||||||
{
|
{
|
||||||
// this will wake up the thread blocked on select, only needed on Linux
|
|
||||||
// _eventfd.notify();
|
|
||||||
|
|
||||||
uint64_t value = 0;
|
uint64_t value = 0;
|
||||||
write(_fildes[1], &value, sizeof(value));
|
write(_fildes[1], &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,10 @@ namespace ix
|
|||||||
return;
|
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)
|
while (true)
|
||||||
{
|
{
|
||||||
ssize_t ret = _socket->recv((char*)&_readbuf[0], _readbuf.size());
|
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
|
_socket->wakeUpFromPoll();
|
||||||
// for large messages.
|
|
||||||
// TODO / this will block the sending thread ; we need to eval whether
|
|
||||||
// this is the right fix
|
|
||||||
while (!isSendBufferEmpty()) sendOnSocket();
|
|
||||||
|
|
||||||
return WebSocketSendInfo(true, compressionError, payloadSize, wireSize);
|
return WebSocketSendInfo(true, compressionError, payloadSize, wireSize);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,13 @@ TEST_CASE("socket", "[socket]")
|
|||||||
std::shared_ptr<Socket> socket(new Socket);
|
std::shared_ptr<Socket> socket(new Socket);
|
||||||
std::string host("www.google.com");
|
std::string host("www.google.com");
|
||||||
int port = 80;
|
int port = 80;
|
||||||
std::string request("GET / HTTP/1.1\r\n\r\n");
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "GET / HTTP/1.1\r\n";
|
||||||
|
ss << "Host: " << host << "\r\n";
|
||||||
|
ss << "\r\n";
|
||||||
|
std::string request(ss.str());
|
||||||
|
|
||||||
int expectedStatus = 200;
|
int expectedStatus = 200;
|
||||||
int timeoutSecs = 3;
|
int timeoutSecs = 3;
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ shutil.copy(os.path.join(
|
|||||||
'zlib.dll'), '.')
|
'zlib.dll'), '.')
|
||||||
|
|
||||||
lldb = "lldb --batch -o 'run' -k 'thread backtrace all' -k 'quit 1'"
|
lldb = "lldb --batch -o 'run' -k 'thread backtrace all' -k 'quit 1'"
|
||||||
|
lldb = "" # Disabled for now
|
||||||
testCommand = '{} {} {}'.format(lldb, testBinary, os.getenv('TEST', ''))
|
testCommand = '{} {} {}'.format(lldb, testBinary, os.getenv('TEST', ''))
|
||||||
ret = os.system(testCommand)
|
ret = os.system(testCommand)
|
||||||
assert ret == 0, 'Test command failed'
|
assert ret == 0, 'Test command failed'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user