Compare commits
3 Commits
feature/ci
...
v11.0.8
Author | SHA1 | Date | |
---|---|---|---|
f6e34e4b34 | |||
d0359a1764 | |||
8910ebcc3c |
2
.github/workflows/unittest_linux.yml
vendored
2
.github/workflows/unittest_linux.yml
vendored
@ -2,7 +2,7 @@ name: linux
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- './**'
|
- 'docs/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
linux:
|
linux:
|
||||||
|
2
.github/workflows/unittest_linux_asan.yml
vendored
2
.github/workflows/unittest_linux_asan.yml
vendored
@ -2,7 +2,7 @@ name: linux_asan
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- './**'
|
- 'docs/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
linux:
|
linux:
|
||||||
|
@ -2,7 +2,7 @@ name: mac_tsan_mbedtls
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- './**'
|
- 'docs/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mac_tsan_mbedtls:
|
mac_tsan_mbedtls:
|
||||||
|
@ -2,7 +2,7 @@ name: mac_tsan_openssl
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- './**'
|
- 'docs/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mac_tsan_openssl:
|
mac_tsan_openssl:
|
||||||
|
@ -2,7 +2,7 @@ name: mac_tsan_sectransport
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- './**'
|
- 'docs/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mac_tsan_sectransport:
|
mac_tsan_sectransport:
|
||||||
|
2
.github/workflows/unittest_uwp.yml
vendored
2
.github/workflows/unittest_uwp.yml
vendored
@ -2,7 +2,7 @@ name: uwp
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- './**'
|
- 'docs/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
uwp:
|
uwp:
|
||||||
|
@ -113,6 +113,10 @@ To check the performance of a websocket library, you can look at the [autoroute]
|
|||||||
| UWP | Disabled | None | [![Build2][6]][0] |
|
| UWP | Disabled | None | [![Build2][6]][0] |
|
||||||
| Linux | OpenSSL | Address Sanitizer | [![Build2][7]][0] |
|
| Linux | OpenSSL | Address Sanitizer | [![Build2][7]][0] |
|
||||||
|
|
||||||
|
* ASAN fails on Linux because of a known problem, we need a
|
||||||
|
* Some tests are disabled on Windows/UWP because of a pathing problem
|
||||||
|
* TLS and ZLIB are disabled on Windows/UWP because enabling make the CI run takes a lot of time, for setting up vcpkg.
|
||||||
|
|
||||||
[0]: https://github.com/machinezone/IXWebSocket
|
[0]: https://github.com/machinezone/IXWebSocket
|
||||||
[1]: https://github.com/machinezone/IXWebSocket/workflows/linux/badge.svg
|
[1]: https://github.com/machinezone/IXWebSocket/workflows/linux/badge.svg
|
||||||
[2]: https://github.com/machinezone/IXWebSocket/workflows/mac_tsan_sectransport/badge.svg
|
[2]: https://github.com/machinezone/IXWebSocket/workflows/mac_tsan_sectransport/badge.svg
|
||||||
|
@ -97,9 +97,10 @@ namespace ix
|
|||||||
}
|
}
|
||||||
else if (_onClientMessageCallback)
|
else if (_onClientMessageCallback)
|
||||||
{
|
{
|
||||||
|
WebSocket* webSocketRawPtr = webSocket.get();
|
||||||
webSocket->setOnMessageCallback(
|
webSocket->setOnMessageCallback(
|
||||||
[this, &ws = *webSocket.get(), connectionState](const WebSocketMessagePtr& msg) {
|
[this, webSocketRawPtr, connectionState](const WebSocketMessagePtr& msg) {
|
||||||
_onClientMessageCallback(connectionState, ws, msg);
|
_onClientMessageCallback(connectionState, *webSocketRawPtr, msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -168,4 +169,45 @@ namespace ix
|
|||||||
std::lock_guard<std::mutex> lock(_clientsMutex);
|
std::lock_guard<std::mutex> lock(_clientsMutex);
|
||||||
return _clients.size();
|
return _clients.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Classic servers
|
||||||
|
//
|
||||||
|
void WebSocketServer::makeBroadcastServer()
|
||||||
|
{
|
||||||
|
setOnClientMessageCallback(
|
||||||
|
[this](std::shared_ptr<ConnectionState> connectionState,
|
||||||
|
WebSocket& webSocket,
|
||||||
|
const WebSocketMessagePtr& msg) {
|
||||||
|
auto remoteIp = connectionState->getRemoteIp();
|
||||||
|
if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
|
{
|
||||||
|
for (auto&& client : getClients())
|
||||||
|
{
|
||||||
|
if (client.get() != &webSocket)
|
||||||
|
{
|
||||||
|
client->send(msg->str, msg->binary);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
size_t bufferedAmount = client->bufferedAmount();
|
||||||
|
std::chrono::duration<double, std::milli> duration(500);
|
||||||
|
std::this_thread::sleep_for(duration);
|
||||||
|
} while (client->bufferedAmount() != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
int WebSocketServer::listenAndStart()
|
||||||
|
{
|
||||||
|
auto res = listen();
|
||||||
|
if (!res.first)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
start();
|
||||||
|
}
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
@ -47,6 +47,9 @@ namespace ix
|
|||||||
// Get all the connected clients
|
// Get all the connected clients
|
||||||
std::set<std::shared_ptr<WebSocket>> getClients();
|
std::set<std::shared_ptr<WebSocket>> getClients();
|
||||||
|
|
||||||
|
void makeBroadcastServer();
|
||||||
|
int listenAndStart();
|
||||||
|
|
||||||
const static int kDefaultHandShakeTimeoutSecs;
|
const static int kDefaultHandShakeTimeoutSecs;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -29,6 +29,7 @@ namespace ix
|
|||||||
|
|
||||||
// Comparison should be case insensitive
|
// Comparison should be case insensitive
|
||||||
REQUIRE(httpHeaders["Foo"] == "foo");
|
REQUIRE(httpHeaders["Foo"] == "foo");
|
||||||
|
REQUIRE(httpHeaders["Foo"] != "bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("2")
|
SECTION("2")
|
||||||
@ -39,7 +40,7 @@ namespace ix
|
|||||||
|
|
||||||
headers["Upgrade"] = "webSocket";
|
headers["Upgrade"] = "webSocket";
|
||||||
|
|
||||||
REQUIRE(CaseInsensitiveLess::cmp(headers["upgrade"], "WebSocket") == 0);
|
REQUIRE(!CaseInsensitiveLess::cmp(headers["upGRADE"], "webSocket"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
99
ws/ws.cpp
99
ws/ws.cpp
@ -439,93 +439,6 @@ namespace ix
|
|||||||
return generateReport(url) ? 0 : 1;
|
return generateReport(url) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// broadcast server
|
|
||||||
//
|
|
||||||
int ws_broadcast_server_main(int port,
|
|
||||||
const std::string& hostname,
|
|
||||||
const ix::SocketTLSOptions& tlsOptions)
|
|
||||||
{
|
|
||||||
spdlog::info("Listening on {}:{}", hostname, port);
|
|
||||||
|
|
||||||
ix::WebSocketServer server(port, hostname);
|
|
||||||
server.setTLSOptions(tlsOptions);
|
|
||||||
|
|
||||||
server.setOnClientMessageCallback(
|
|
||||||
[&server](std::shared_ptr<ConnectionState> connectionState,
|
|
||||||
WebSocket& webSocket,
|
|
||||||
const WebSocketMessagePtr& msg) {
|
|
||||||
auto remoteIp = connectionState->getRemoteIp();
|
|
||||||
if (msg->type == ix::WebSocketMessageType::Open)
|
|
||||||
{
|
|
||||||
spdlog::info("New connection");
|
|
||||||
spdlog::info("remote ip: {}", remoteIp);
|
|
||||||
spdlog::info("id: {}", connectionState->getId());
|
|
||||||
spdlog::info("Uri: {}", msg->openInfo.uri);
|
|
||||||
spdlog::info("Headers:");
|
|
||||||
for (auto it : msg->openInfo.headers)
|
|
||||||
{
|
|
||||||
spdlog::info("{}: {}", it.first, it.second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (msg->type == ix::WebSocketMessageType::Close)
|
|
||||||
{
|
|
||||||
spdlog::info("Closed connection: code {} reason {}",
|
|
||||||
msg->closeInfo.code,
|
|
||||||
msg->closeInfo.reason);
|
|
||||||
}
|
|
||||||
else if (msg->type == ix::WebSocketMessageType::Error)
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "Connection error: " << msg->errorInfo.reason << std::endl;
|
|
||||||
ss << "#retries: " << msg->errorInfo.retries << std::endl;
|
|
||||||
ss << "Wait time(ms): " << msg->errorInfo.wait_time << std::endl;
|
|
||||||
ss << "HTTP Status: " << msg->errorInfo.http_status << std::endl;
|
|
||||||
spdlog::info(ss.str());
|
|
||||||
}
|
|
||||||
else if (msg->type == ix::WebSocketMessageType::Fragment)
|
|
||||||
{
|
|
||||||
spdlog::info("Received message fragment");
|
|
||||||
}
|
|
||||||
else if (msg->type == ix::WebSocketMessageType::Message)
|
|
||||||
{
|
|
||||||
spdlog::info("Received {} bytes", msg->wireSize);
|
|
||||||
|
|
||||||
for (auto&& client : server.getClients())
|
|
||||||
{
|
|
||||||
if (client.get() != &webSocket)
|
|
||||||
{
|
|
||||||
client->send(msg->str, msg->binary, [](int current, int total) -> bool {
|
|
||||||
spdlog::info("Step {} out of {}", current, total);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
size_t bufferedAmount = client->bufferedAmount();
|
|
||||||
spdlog::info("{} bytes left to be sent", bufferedAmount);
|
|
||||||
|
|
||||||
std::chrono::duration<double, std::milli> duration(500);
|
|
||||||
std::this_thread::sleep_for(duration);
|
|
||||||
} while (client->bufferedAmount() != 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
auto res = server.listen();
|
|
||||||
if (!res.first)
|
|
||||||
{
|
|
||||||
spdlog::info(res.second);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
server.start();
|
|
||||||
server.wait();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ws_chat.cpp
|
* ws_chat.cpp
|
||||||
* Author: Benjamin Sergeant
|
* Author: Benjamin Sergeant
|
||||||
@ -2853,9 +2766,13 @@ int main(int argc, char** argv)
|
|||||||
ret = ix::ws_push_server(
|
ret = ix::ws_push_server(
|
||||||
port, hostname, tlsOptions, ipv6, disablePerMessageDeflate, disablePong, sendMsg);
|
port, hostname, tlsOptions, ipv6, disablePerMessageDeflate, disablePong, sendMsg);
|
||||||
}
|
}
|
||||||
else if (app.got_subcommand("transfer"))
|
else if (app.got_subcommand("transfer") || app.got_subcommand("broadcast_server"))
|
||||||
{
|
{
|
||||||
ret = ix::ws_transfer_main(port, hostname, tlsOptions);
|
ix::WebSocketServer server(port, hostname);
|
||||||
|
server.setTLSOptions(tlsOptions);
|
||||||
|
server.makeBroadcastServer();
|
||||||
|
server.listenAndStart();
|
||||||
|
server.wait();
|
||||||
}
|
}
|
||||||
else if (app.got_subcommand("send"))
|
else if (app.got_subcommand("send"))
|
||||||
{
|
{
|
||||||
@ -2870,10 +2787,6 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
ret = ix::ws_chat_main(url, user);
|
ret = ix::ws_chat_main(url, user);
|
||||||
}
|
}
|
||||||
else if (app.got_subcommand("broadcast_server"))
|
|
||||||
{
|
|
||||||
ret = ix::ws_broadcast_server_main(port, hostname, tlsOptions);
|
|
||||||
}
|
|
||||||
else if (app.got_subcommand("ping"))
|
else if (app.got_subcommand("ping"))
|
||||||
{
|
{
|
||||||
ret = ix::ws_ping_pong_main(url, tlsOptions);
|
ret = ix::ws_ping_pong_main(url, tlsOptions);
|
||||||
|
Reference in New Issue
Block a user