Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
e15a2900e7 | |||
140a21c8b3 | |||
6d0c568aaa | |||
c96abcef1c | |||
4a9b0b9dfd | |||
8837d5e784 |
2
.github/workflows/ccpp.yml
vendored
2
.github/workflows/ccpp.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
name: C/C++ CI
|
name: unittest
|
||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
## Hello world
|
## Hello world
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
IXWebSocket is a C++ library for WebSocket client and server development. It has minimal dependencies (no boost), is very simple to use and support everything you'll likely need for websocket dev (SSL, deflate compression, compiles on most platforms, etc...). HTTP client and server code is also available, but it hasn't received as much testing.
|
IXWebSocket is a C++ library for WebSocket client and server development. It has minimal dependencies (no boost), is very simple to use and support everything you'll likely need for websocket dev (SSL, deflate compression, compiles on most platforms, etc...). HTTP client and server code is also available, but it hasn't received as much testing.
|
||||||
|
|
||||||
|
@ -1,6 +1,22 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All changes to this project will be documented in this file.
|
All changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [8.1.7] - 2020-02-26
|
||||||
|
|
||||||
|
(websocket) traffic tracker received bytes is message size while it should be wire size
|
||||||
|
|
||||||
|
## [8.1.6] - 2020-02-26
|
||||||
|
|
||||||
|
(ws_connect) display sent/received bytes statistics on exit
|
||||||
|
|
||||||
|
## [8.1.5] - 2020-02-23
|
||||||
|
|
||||||
|
(server) give thread name to some usual worker threads / unittest is broken !!
|
||||||
|
|
||||||
|
## [8.1.4] - 2020-02-22
|
||||||
|
|
||||||
|
(websocket server) fix regression from 8.1.2, where per-deflate message compression was always disabled
|
||||||
|
|
||||||
## [8.1.3] - 2020-02-21
|
## [8.1.3] - 2020-02-21
|
||||||
|
|
||||||
(client + server) Fix #155 / http header parser should treat the space(s) after the : delimiter as optional. Fixing this bug made us discover that websocket sub-protocols are not properly serialiazed, but start with a ,
|
(client + server) Fix #155 / http header parser should treat the space(s) after the : delimiter as optional. Fixing this bug made us discover that websocket sub-protocols are not properly serialiazed, but start with a ,
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "IXSocketServer.h"
|
#include "IXSocketServer.h"
|
||||||
|
|
||||||
#include "IXNetSystem.h"
|
#include "IXNetSystem.h"
|
||||||
|
#include "IXSetThreadName.h"
|
||||||
#include "IXSocket.h"
|
#include "IXSocket.h"
|
||||||
#include "IXSocketConnect.h"
|
#include "IXSocketConnect.h"
|
||||||
#include "IXSocketFactory.h"
|
#include "IXSocketFactory.h"
|
||||||
@ -247,6 +248,8 @@ namespace ix
|
|||||||
// Set the socket to non blocking mode, so that accept calls are not blocking
|
// Set the socket to non blocking mode, so that accept calls are not blocking
|
||||||
SocketConnect::configure(_serverFd);
|
SocketConnect::configure(_serverFd);
|
||||||
|
|
||||||
|
setThreadName("SocketServer::listen");
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (_stop) return;
|
if (_stop) return;
|
||||||
@ -347,6 +350,8 @@ namespace ix
|
|||||||
|
|
||||||
void SocketServer::runGC()
|
void SocketServer::runGC()
|
||||||
{
|
{
|
||||||
|
setThreadName("SocketServer::GC");
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
// Garbage collection to shutdown/join threads for closed connections.
|
// Garbage collection to shutdown/join threads for closed connections.
|
||||||
|
@ -134,6 +134,13 @@ namespace ix
|
|||||||
_enablePong = false;
|
_enablePong = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebSocket::enablePerMessageDeflate()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_configMutex);
|
||||||
|
WebSocketPerMessageDeflateOptions perMessageDeflateOptions(true);
|
||||||
|
_perMessageDeflateOptions = perMessageDeflateOptions;
|
||||||
|
}
|
||||||
|
|
||||||
void WebSocket::disablePerMessageDeflate()
|
void WebSocket::disablePerMessageDeflate()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_configMutex);
|
std::lock_guard<std::mutex> lock(_configMutex);
|
||||||
@ -405,7 +412,7 @@ namespace ix
|
|||||||
WebSocketCloseInfo(),
|
WebSocketCloseInfo(),
|
||||||
binary));
|
binary));
|
||||||
|
|
||||||
WebSocket::invokeTrafficTrackerCallback(msg.size(), true);
|
WebSocket::invokeTrafficTrackerCallback(wireSize, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ namespace ix
|
|||||||
void setPingTimeout(int pingTimeoutSecs);
|
void setPingTimeout(int pingTimeoutSecs);
|
||||||
void enablePong();
|
void enablePong();
|
||||||
void disablePong();
|
void disablePong();
|
||||||
|
void enablePerMessageDeflate();
|
||||||
void disablePerMessageDeflate();
|
void disablePerMessageDeflate();
|
||||||
void addSubProtocol(const std::string& subProtocol);
|
void addSubProtocol(const std::string& subProtocol);
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ namespace ix
|
|||||||
WebSocketInitResult connect(int timeoutSecs);
|
WebSocketInitResult connect(int timeoutSecs);
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
// send is in binary mode by default
|
// send is in text mode by default
|
||||||
WebSocketSendInfo send(const std::string& data,
|
WebSocketSendInfo send(const std::string& data,
|
||||||
bool binary = false,
|
bool binary = false,
|
||||||
const OnProgressCallback& onProgressCallback = nullptr);
|
const OnProgressCallback& onProgressCallback = nullptr);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "IXWebSocketServer.h"
|
#include "IXWebSocketServer.h"
|
||||||
|
|
||||||
#include "IXNetSystem.h"
|
#include "IXNetSystem.h"
|
||||||
|
#include "IXSetThreadName.h"
|
||||||
#include "IXSocketConnect.h"
|
#include "IXSocketConnect.h"
|
||||||
#include "IXWebSocket.h"
|
#include "IXWebSocket.h"
|
||||||
#include "IXWebSocketTransport.h"
|
#include "IXWebSocketTransport.h"
|
||||||
@ -73,6 +74,8 @@ namespace ix
|
|||||||
void WebSocketServer::handleConnection(std::shared_ptr<Socket> socket,
|
void WebSocketServer::handleConnection(std::shared_ptr<Socket> socket,
|
||||||
std::shared_ptr<ConnectionState> connectionState)
|
std::shared_ptr<ConnectionState> connectionState)
|
||||||
{
|
{
|
||||||
|
setThreadName("WebSocketServer::" + connectionState->getId());
|
||||||
|
|
||||||
auto webSocket = std::make_shared<WebSocket>();
|
auto webSocket = std::make_shared<WebSocket>();
|
||||||
_onConnectionCallback(webSocket, connectionState);
|
_onConnectionCallback(webSocket, connectionState);
|
||||||
|
|
||||||
@ -87,7 +90,11 @@ namespace ix
|
|||||||
webSocket->disablePong();
|
webSocket->disablePong();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_enablePerMessageDeflate)
|
if (_enablePerMessageDeflate)
|
||||||
|
{
|
||||||
|
webSocket->enablePerMessageDeflate();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
webSocket->disablePerMessageDeflate();
|
webSocket->disablePerMessageDeflate();
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "8.1.3"
|
#define IX_WEBSOCKET_VERSION "8.1.7"
|
||||||
|
@ -30,6 +30,9 @@ namespace ix
|
|||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
int getSentBytes() { return _sentBytes; }
|
||||||
|
int getReceivedBytes() { return _receivedBytes; }
|
||||||
|
|
||||||
void sendMessage(const std::string& text);
|
void sendMessage(const std::string& text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -38,6 +41,8 @@ namespace ix
|
|||||||
ix::WebSocket _webSocket;
|
ix::WebSocket _webSocket;
|
||||||
bool _disablePerMessageDeflate;
|
bool _disablePerMessageDeflate;
|
||||||
bool _binaryMode;
|
bool _binaryMode;
|
||||||
|
std::atomic<int> _receivedBytes;
|
||||||
|
std::atomic<int> _sentBytes;
|
||||||
|
|
||||||
void log(const std::string& msg);
|
void log(const std::string& msg);
|
||||||
WebSocketHttpHeaders parseHeaders(const std::string& data);
|
WebSocketHttpHeaders parseHeaders(const std::string& data);
|
||||||
@ -54,6 +59,8 @@ namespace ix
|
|||||||
: _url(url)
|
: _url(url)
|
||||||
, _disablePerMessageDeflate(disablePerMessageDeflate)
|
, _disablePerMessageDeflate(disablePerMessageDeflate)
|
||||||
, _binaryMode(binaryMode)
|
, _binaryMode(binaryMode)
|
||||||
|
, _receivedBytes(0)
|
||||||
|
, _sentBytes(0)
|
||||||
{
|
{
|
||||||
if (disableAutomaticReconnection)
|
if (disableAutomaticReconnection)
|
||||||
{
|
{
|
||||||
@ -68,6 +75,20 @@ namespace ix
|
|||||||
{
|
{
|
||||||
_webSocket.addSubProtocol(subprotocol);
|
_webSocket.addSubProtocol(subprotocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebSocket::setTrafficTrackerCallback(
|
||||||
|
[this](int size, bool incoming)
|
||||||
|
{
|
||||||
|
if (incoming)
|
||||||
|
{
|
||||||
|
_receivedBytes += size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_sentBytes += size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocketConnect::log(const std::string& msg)
|
void WebSocketConnect::log(const std::string& msg)
|
||||||
@ -246,6 +267,9 @@ namespace ix
|
|||||||
spdlog::info("");
|
spdlog::info("");
|
||||||
webSocketChat.stop();
|
webSocketChat.stop();
|
||||||
|
|
||||||
|
spdlog::info("Received {} bytes", webSocketChat.getReceivedBytes());
|
||||||
|
spdlog::info("Sent {} bytes", webSocketChat.getSentBytes());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
Reference in New Issue
Block a user