Feature/send large message (#14)

* introduce send fragment

* can pass a fin frame

* can send messages which are a perfect multiple of the chunk size

* set fin only for last fragment

* cleanup

* last fragment should be of type CONTINUATION

* Add simple send and receive programs

* speedups receiving + better way to wait for thing

* receive speedup by using linked list of chunks instead of large array

* document bug

* use chunks to receive data

* trailing spaces
This commit is contained in:
Benjamin Sergeant
2019-02-20 18:59:07 -08:00
committed by GitHub
parent dd4e29542c
commit 932bb732e0
72 changed files with 9117 additions and 260 deletions

View File

@ -79,7 +79,7 @@ namespace
return _receivedMessages;
}
void WebSocketChat::appendMessage(const std::string& message)
void WebSocketChat::appendMessage(const std::string& message)
{
std::lock_guard<std::mutex> lock(_mutex);
_receivedMessages.push_back(message);
@ -101,7 +101,7 @@ namespace
{
std::stringstream ss;
ss << "ws://localhost:"
<< _port
<< _port
<< "/"
<< _user;
@ -150,10 +150,10 @@ namespace
std::string payload = result.second;
if (payload.size() > 2000)
{
payload = "<message too large>";
payload = "<message too large>";
}
ss << std::endl
ss << std::endl
<< result.first << " > " << payload
<< std::endl
<< _user << " > ";
@ -293,12 +293,13 @@ TEST_CASE("Websocket_chat", "[websocket_chat]")
chatB.sendMessage("from B1");
chatB.sendMessage("from B2");
// FIXME: cannot handle large message, we need to break them down
// into small one at the websocket layer (using CONTINUATION opcode)
size_t size = 512 * 1000; // 512K is OK, larger is not !!
// Test large messages that needs to be broken into small fragments
size_t size = 1 * 1024 * 1024; // ~1Mb
std::string bigMessage(size, 'a');
chatB.sendMessage(bigMessage);
log("Sent all messages");
// Wait until all messages are received. 10s timeout
int attempts = 0;
while (chatA.getReceivedMessagesCount() != 3 ||