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
parent 8d819053ff
commit a0a53ab986
72 changed files with 9116 additions and 259 deletions

View File

@ -16,7 +16,7 @@
# endif
#endif
#include "IXTest.h"
#include "IXTest.h"
#include "catch.hpp"
using namespace ix;

View File

@ -57,7 +57,7 @@ namespace ix
std::string generateSessionId()
{
auto now = std::chrono::system_clock::now();
auto seconds =
auto seconds =
std::chrono::duration_cast<std::chrono::seconds>(
now.time_since_epoch()).count();
@ -73,7 +73,7 @@ namespace ix
{
int defaultPort = 8090;
int sockfd;
int sockfd;
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
log("Cannot compute a free port. socket error.");

View File

@ -34,7 +34,7 @@ namespace
int _port;
};
WebSocketClient::WebSocketClient(int port)
WebSocketClient::WebSocketClient(int port)
: _port(port)
{
;
@ -56,7 +56,7 @@ namespace
{
std::stringstream ss;
ss << "ws://localhost:"
<< _port
<< _port
<< "/";
url = ss.str();
@ -64,7 +64,7 @@ namespace
_webSocket.setUrl(url);
// The important bit for this test.
// The important bit for this test.
// Set a 1 second hearbeat ; if no traffic is present on the connection for 1 second
// a ping message will be sent by the client.
_webSocket.setHeartBeatPeriod(1);

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 ||

View File

@ -20,7 +20,7 @@ if osName == 'Windows':
else:
generator = ''
make = 'make -j6'
testBinary ='./ixwebsocket_unittest'
testBinary ='./ixwebsocket_unittest'
sanitizersFlags = {
'asan': '-DSANITIZE_ADDRESS=On',

View File

@ -9,7 +9,7 @@
#include <ixwebsocket/IXSocket.h>
int main(int argc, char* argv[])
int main(int argc, char* argv[])
{
ix::Socket::init(); // for Windows