Compare commits
6 Commits
v11.0.9
...
feature/ci
Author | SHA1 | Date | |
---|---|---|---|
84163ad19e | |||
5e5b7c34ca | |||
9bb1de64a4 | |||
df9889947d | |||
6ede8c85b0 | |||
2663f605f4 |
2
.github/workflows/unittest_linux.yml
vendored
2
.github/workflows/unittest_linux.yml
vendored
@ -2,7 +2,7 @@ name: linux
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- './**'
|
||||
|
||||
jobs:
|
||||
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:
|
||||
push:
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- './**'
|
||||
|
||||
jobs:
|
||||
linux:
|
||||
|
@ -2,7 +2,7 @@ name: mac_tsan_mbedtls
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- './**'
|
||||
|
||||
jobs:
|
||||
mac_tsan_mbedtls:
|
||||
|
@ -2,7 +2,7 @@ name: mac_tsan_openssl
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- './**'
|
||||
|
||||
jobs:
|
||||
mac_tsan_openssl:
|
||||
|
@ -2,7 +2,7 @@ name: mac_tsan_sectransport
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- './**'
|
||||
|
||||
jobs:
|
||||
mac_tsan_sectransport:
|
||||
|
2
.github/workflows/unittest_uwp.yml
vendored
2
.github/workflows/unittest_uwp.yml
vendored
@ -2,7 +2,7 @@ name: uwp
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- './**'
|
||||
|
||||
jobs:
|
||||
uwp:
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,4 +7,3 @@ ws/.certs/
|
||||
ws/.srl
|
||||
ixhttpd
|
||||
makefile
|
||||
a.out
|
||||
|
@ -191,7 +191,7 @@ if (USE_TLS)
|
||||
target_link_libraries(ixwebsocket ${MBEDTLS_LIBRARIES})
|
||||
elseif (USE_SECURE_TRANSPORT)
|
||||
message(STATUS "TLS configured to use secure transport")
|
||||
target_link_libraries(ixwebsocket "-framework Foundation" "-framework Security")
|
||||
target_link_libraries(ixwebsocket "-framework foundation" "-framework security")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
25
README.md
25
README.md
@ -15,8 +15,8 @@ A bad security bug affecting users compiling with SSL enabled and OpenSSL as the
|
||||
* Super simple standalone example. See ws folder, unittest and doc/usage.md for more.
|
||||
*
|
||||
* On macOS
|
||||
* $ mkdir -p build ; (cd build ; cmake -DUSE_TLS=1 .. ; make -j ; make install)
|
||||
* $ clang++ --std=c++11 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
|
||||
* $ mkdir -p build ; cd build ; cmake -DUSE_TLS=1 .. ; make -j ; make install
|
||||
* $ clang++ --std=c++14 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
|
||||
* $ ./a.out
|
||||
*/
|
||||
|
||||
@ -44,12 +44,10 @@ int main()
|
||||
if (msg->type == ix::WebSocketMessageType::Message)
|
||||
{
|
||||
std::cout << "received message: " << msg->str << std::endl;
|
||||
std::cout << "> " << std::flush;
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Open)
|
||||
{
|
||||
std::cout << "Connection established" << std::endl;
|
||||
std::cout << "> " << std::flush;
|
||||
}
|
||||
}
|
||||
);
|
||||
@ -60,16 +58,13 @@ int main()
|
||||
// Send a message to the server (default to TEXT mode)
|
||||
webSocket.send("hello world");
|
||||
|
||||
// Display a prompt
|
||||
std::cout << "> " << std::flush;
|
||||
|
||||
std::string text;
|
||||
// Read text from the console and send messages in text mode.
|
||||
// Exit with Ctrl-D on Unix or Ctrl-Z on Windows.
|
||||
while (std::getline(std::cin, text))
|
||||
while (true)
|
||||
{
|
||||
webSocket.send(text);
|
||||
std::string text;
|
||||
std::cout << "> " << std::flush;
|
||||
std::getline(std::cin, text);
|
||||
|
||||
webSocket.send(text);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -82,8 +77,6 @@ IXWebSocket is actively being developed, check out the [changelog](https://machi
|
||||
|
||||
IXWebSocket client code is autobahn compliant beginning with the 6.0.0 version. See the current [test results](https://bsergean.github.io/autobahn/reports/clients/index.html). Some tests are still failing in the server code.
|
||||
|
||||
Starting with the 11.0.8 release, IXWebSocket should be fully C++11 compatible.
|
||||
|
||||
## Users
|
||||
|
||||
If your company or project is using this library, feel free to open an issue or PR to amend this list.
|
||||
@ -120,10 +113,6 @@ To check the performance of a websocket library, you can look at the [autoroute]
|
||||
| UWP | Disabled | None | [![Build2][6]][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
|
||||
[1]: https://github.com/machinezone/IXWebSocket/workflows/linux/badge.svg
|
||||
[2]: https://github.com/machinezone/IXWebSocket/workflows/mac_tsan_sectransport/badge.svg
|
||||
|
@ -2,10 +2,6 @@
|
||||
|
||||
All changes to this project will be documented in this file.
|
||||
|
||||
## [11.0.9] - 2021-03-07
|
||||
|
||||
(ixwebsocket) Expose setHandshakeTimeout method
|
||||
|
||||
## [11.0.8] - 2020-12-25
|
||||
|
||||
(ws) trim ws dependencies no more ixcrypto and ixcore deps
|
||||
|
@ -263,15 +263,6 @@ webSocket.setMaxWaitBetweenReconnectionRetries(5 * 1000); // 5000ms = 5s
|
||||
uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries();
|
||||
```
|
||||
|
||||
## Handshake timeout
|
||||
|
||||
You can control how long to wait until timing out while waiting for the websocket handshake to be performed.
|
||||
|
||||
```
|
||||
int handshakeTimeoutSecs = 1;
|
||||
setHandshakeTimeout(handshakeTimeoutSecs);
|
||||
```
|
||||
|
||||
## WebSocket server API
|
||||
|
||||
### Legacy api
|
||||
|
@ -56,11 +56,6 @@ namespace ix
|
||||
_url = url;
|
||||
}
|
||||
|
||||
void WebSocket::setHandshakeTimeout(int handshakeTimeoutSecs)
|
||||
{
|
||||
_handshakeTimeoutSecs = handshakeTimeoutSecs;
|
||||
}
|
||||
|
||||
void WebSocket::setExtraHeaders(const WebSocketHttpHeaders& headers)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_configMutex);
|
||||
|
@ -58,7 +58,6 @@ namespace ix
|
||||
void enablePerMessageDeflate();
|
||||
void disablePerMessageDeflate();
|
||||
void addSubProtocol(const std::string& subProtocol);
|
||||
void setHandshakeTimeout(int handshakeTimeoutSecs);
|
||||
|
||||
// Run asynchronously, by calling start and stop.
|
||||
void start();
|
||||
|
@ -97,10 +97,9 @@ namespace ix
|
||||
}
|
||||
else if (_onClientMessageCallback)
|
||||
{
|
||||
WebSocket* webSocketRawPtr = webSocket.get();
|
||||
webSocket->setOnMessageCallback(
|
||||
[this, webSocketRawPtr, connectionState](const WebSocketMessagePtr& msg) {
|
||||
_onClientMessageCallback(connectionState, *webSocketRawPtr, msg);
|
||||
[this, &ws = *webSocket.get(), connectionState](const WebSocketMessagePtr& msg) {
|
||||
_onClientMessageCallback(connectionState, ws, msg);
|
||||
});
|
||||
}
|
||||
else
|
||||
@ -169,45 +168,4 @@ namespace ix
|
||||
std::lock_guard<std::mutex> lock(_clientsMutex);
|
||||
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);
|
||||
|
||||
// Make sure the OS send buffer is flushed before moving on
|
||||
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
|
||||
|
@ -47,9 +47,6 @@ namespace ix
|
||||
// Get all the connected clients
|
||||
std::set<std::shared_ptr<WebSocket>> getClients();
|
||||
|
||||
void makeBroadcastServer();
|
||||
int listenAndStart();
|
||||
|
||||
const static int kDefaultHandShakeTimeoutSecs;
|
||||
|
||||
private:
|
||||
|
@ -6,4 +6,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define IX_WEBSOCKET_VERSION "11.0.9"
|
||||
#define IX_WEBSOCKET_VERSION "11.0.8"
|
||||
|
15
main.cpp
15
main.cpp
@ -35,12 +35,10 @@ int main()
|
||||
if (msg->type == ix::WebSocketMessageType::Message)
|
||||
{
|
||||
std::cout << "received message: " << msg->str << std::endl;
|
||||
std::cout << "> " << std::flush;
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Open)
|
||||
{
|
||||
std::cout << "Connection established" << std::endl;
|
||||
std::cout << "> " << std::flush;
|
||||
}
|
||||
}
|
||||
);
|
||||
@ -51,16 +49,13 @@ int main()
|
||||
// Send a message to the server (default to TEXT mode)
|
||||
webSocket.send("hello world");
|
||||
|
||||
// Display a prompt
|
||||
std::cout << "> " << std::flush;
|
||||
|
||||
std::string text;
|
||||
// Read text from the console and send messages in text mode.
|
||||
// Exit with Ctrl-D on Unix or Ctrl-Z on Windows.
|
||||
while (std::getline(std::cin, text))
|
||||
while (true)
|
||||
{
|
||||
webSocket.send(text);
|
||||
std::string text;
|
||||
std::cout << "> " << std::flush;
|
||||
std::getline(std::cin, text);
|
||||
|
||||
webSocket.send(text);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -33,7 +33,11 @@ TEST_CASE("dns", "[net]")
|
||||
auto dnsLookup = std::make_shared<DNSLookup>("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80);
|
||||
|
||||
std::string errMsg;
|
||||
struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return false; });
|
||||
struct addrinfo* res = dnsLookup->resolve(errMsg,
|
||||
[]
|
||||
{
|
||||
return false;
|
||||
});
|
||||
std::cerr << "Error message: " << errMsg << std::endl;
|
||||
REQUIRE(res == nullptr);
|
||||
}
|
||||
@ -44,7 +48,11 @@ TEST_CASE("dns", "[net]")
|
||||
|
||||
std::string errMsg;
|
||||
// The callback returning true means we are requesting cancellation
|
||||
struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return true; });
|
||||
struct addrinfo* res = dnsLookup->resolve(errMsg,
|
||||
[]
|
||||
{
|
||||
return true;
|
||||
});
|
||||
std::cerr << "Error message: " << errMsg << std::endl;
|
||||
REQUIRE(res == nullptr);
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ namespace ix
|
||||
|
||||
// Comparison should be case insensitive
|
||||
REQUIRE(httpHeaders["Foo"] == "foo");
|
||||
REQUIRE(httpHeaders["Foo"] != "bar");
|
||||
}
|
||||
|
||||
SECTION("2")
|
||||
@ -40,7 +39,7 @@ namespace ix
|
||||
|
||||
headers["Upgrade"] = "webSocket";
|
||||
|
||||
REQUIRE(!CaseInsensitiveLess::cmp(headers["upGRADE"], "webSocket"));
|
||||
REQUIRE(CaseInsensitiveLess::cmp(headers["upgrade"], "WebSocket") == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
108
ws/ws.cpp
108
ws/ws.cpp
@ -439,6 +439,93 @@ namespace ix
|
||||
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
|
||||
* Author: Benjamin Sergeant
|
||||
@ -901,9 +988,6 @@ namespace ix
|
||||
|
||||
auto addr = res->ai_addr;
|
||||
|
||||
// FIXME: this display weird addresses / we could steal libuv inet.c
|
||||
// code which display correct results
|
||||
|
||||
char str[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &addr, str, INET_ADDRSTRLEN);
|
||||
|
||||
@ -2378,9 +2462,9 @@ namespace ix
|
||||
else
|
||||
{
|
||||
std::string readyStateString =
|
||||
readyState == ReadyState::Connecting ? "Connecting"
|
||||
: readyState == ReadyState::Closing ? "Closing"
|
||||
: "Closed";
|
||||
readyState == ReadyState::Connecting
|
||||
? "Connecting"
|
||||
: readyState == ReadyState::Closing ? "Closing" : "Closed";
|
||||
size_t bufferedAmount = client->bufferedAmount();
|
||||
|
||||
spdlog::info(
|
||||
@ -2769,13 +2853,9 @@ int main(int argc, char** argv)
|
||||
ret = ix::ws_push_server(
|
||||
port, hostname, tlsOptions, ipv6, disablePerMessageDeflate, disablePong, sendMsg);
|
||||
}
|
||||
else if (app.got_subcommand("transfer") || app.got_subcommand("broadcast_server"))
|
||||
else if (app.got_subcommand("transfer"))
|
||||
{
|
||||
ix::WebSocketServer server(port, hostname);
|
||||
server.setTLSOptions(tlsOptions);
|
||||
server.makeBroadcastServer();
|
||||
server.listenAndStart();
|
||||
server.wait();
|
||||
ret = ix::ws_transfer_main(port, hostname, tlsOptions);
|
||||
}
|
||||
else if (app.got_subcommand("send"))
|
||||
{
|
||||
@ -2790,6 +2870,10 @@ int main(int argc, char** argv)
|
||||
{
|
||||
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"))
|
||||
{
|
||||
ret = ix::ws_ping_pong_main(url, tlsOptions);
|
||||
|
Reference in New Issue
Block a user