Compare commits
6 Commits
bug/docker
...
v11.0.9
Author | SHA1 | Date | |
---|---|---|---|
f090c7659b | |||
7c195219cd | |||
d739662a7c | |||
e7f7e470e2 | |||
d239738ec6 | |||
c61975bf75 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ ws/.certs/
|
|||||||
ws/.srl
|
ws/.srl
|
||||||
ixhttpd
|
ixhttpd
|
||||||
makefile
|
makefile
|
||||||
|
a.out
|
||||||
|
@ -191,7 +191,7 @@ if (USE_TLS)
|
|||||||
target_link_libraries(ixwebsocket ${MBEDTLS_LIBRARIES})
|
target_link_libraries(ixwebsocket ${MBEDTLS_LIBRARIES})
|
||||||
elseif (USE_SECURE_TRANSPORT)
|
elseif (USE_SECURE_TRANSPORT)
|
||||||
message(STATUS "TLS configured to 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()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
19
README.md
19
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.
|
* Super simple standalone example. See ws folder, unittest and doc/usage.md for more.
|
||||||
*
|
*
|
||||||
* On macOS
|
* On macOS
|
||||||
* $ mkdir -p build ; cd build ; cmake -DUSE_TLS=1 .. ; make -j ; make install
|
* $ 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
|
* $ clang++ --std=c++11 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
|
||||||
* $ ./a.out
|
* $ ./a.out
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -44,10 +44,12 @@ int main()
|
|||||||
if (msg->type == ix::WebSocketMessageType::Message)
|
if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
{
|
{
|
||||||
std::cout << "received message: " << msg->str << std::endl;
|
std::cout << "received message: " << msg->str << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
else if (msg->type == ix::WebSocketMessageType::Open)
|
else if (msg->type == ix::WebSocketMessageType::Open)
|
||||||
{
|
{
|
||||||
std::cout << "Connection established" << std::endl;
|
std::cout << "Connection established" << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -58,13 +60,16 @@ int main()
|
|||||||
// Send a message to the server (default to TEXT mode)
|
// Send a message to the server (default to TEXT mode)
|
||||||
webSocket.send("hello world");
|
webSocket.send("hello world");
|
||||||
|
|
||||||
while (true)
|
// Display a prompt
|
||||||
{
|
std::cout << "> " << std::flush;
|
||||||
std::string text;
|
|
||||||
std::cout << "> " << std::flush;
|
|
||||||
std::getline(std::cin, text);
|
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
webSocket.send(text);
|
webSocket.send(text);
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
All changes to this project will be documented in this file.
|
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
|
## [11.0.8] - 2020-12-25
|
||||||
|
|
||||||
(ws) trim ws dependencies no more ixcrypto and ixcore deps
|
(ws) trim ws dependencies no more ixcrypto and ixcore deps
|
||||||
|
@ -263,6 +263,15 @@ webSocket.setMaxWaitBetweenReconnectionRetries(5 * 1000); // 5000ms = 5s
|
|||||||
uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries();
|
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
|
## WebSocket server API
|
||||||
|
|
||||||
### Legacy api
|
### Legacy api
|
||||||
|
@ -56,6 +56,11 @@ namespace ix
|
|||||||
_url = url;
|
_url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebSocket::setHandshakeTimeout(int handshakeTimeoutSecs)
|
||||||
|
{
|
||||||
|
_handshakeTimeoutSecs = handshakeTimeoutSecs;
|
||||||
|
}
|
||||||
|
|
||||||
void WebSocket::setExtraHeaders(const WebSocketHttpHeaders& headers)
|
void WebSocket::setExtraHeaders(const WebSocketHttpHeaders& headers)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_configMutex);
|
std::lock_guard<std::mutex> lock(_configMutex);
|
||||||
|
@ -58,6 +58,7 @@ namespace ix
|
|||||||
void enablePerMessageDeflate();
|
void enablePerMessageDeflate();
|
||||||
void disablePerMessageDeflate();
|
void disablePerMessageDeflate();
|
||||||
void addSubProtocol(const std::string& subProtocol);
|
void addSubProtocol(const std::string& subProtocol);
|
||||||
|
void setHandshakeTimeout(int handshakeTimeoutSecs);
|
||||||
|
|
||||||
// Run asynchronously, by calling start and stop.
|
// Run asynchronously, by calling start and stop.
|
||||||
void start();
|
void start();
|
||||||
|
@ -175,30 +175,29 @@ namespace ix
|
|||||||
//
|
//
|
||||||
void WebSocketServer::makeBroadcastServer()
|
void WebSocketServer::makeBroadcastServer()
|
||||||
{
|
{
|
||||||
setOnClientMessageCallback(
|
setOnClientMessageCallback([this](std::shared_ptr<ConnectionState> connectionState,
|
||||||
[this](std::shared_ptr<ConnectionState> connectionState,
|
WebSocket& webSocket,
|
||||||
WebSocket& webSocket,
|
const WebSocketMessagePtr& msg) {
|
||||||
const WebSocketMessagePtr& msg) {
|
auto remoteIp = connectionState->getRemoteIp();
|
||||||
auto remoteIp = connectionState->getRemoteIp();
|
if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
if (msg->type == ix::WebSocketMessageType::Message)
|
{
|
||||||
|
for (auto&& client : getClients())
|
||||||
{
|
{
|
||||||
for (auto&& client : getClients())
|
if (client.get() != &webSocket)
|
||||||
{
|
{
|
||||||
if (client.get() != &webSocket)
|
client->send(msg->str, msg->binary);
|
||||||
{
|
|
||||||
client->send(msg->str, msg->binary);
|
|
||||||
|
|
||||||
// Make sure the OS send buffer is flushed before moving on
|
// Make sure the OS send buffer is flushed before moving on
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
size_t bufferedAmount = client->bufferedAmount();
|
size_t bufferedAmount = client->bufferedAmount();
|
||||||
std::chrono::duration<double, std::milli> duration(500);
|
std::chrono::duration<double, std::milli> duration(500);
|
||||||
std::this_thread::sleep_for(duration);
|
std::this_thread::sleep_for(duration);
|
||||||
} while (client->bufferedAmount() != 0);
|
} while (client->bufferedAmount() != 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebSocketServer::listenAndStart()
|
int WebSocketServer::listenAndStart()
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "11.0.8"
|
#define IX_WEBSOCKET_VERSION "11.0.9"
|
||||||
|
15
main.cpp
15
main.cpp
@ -35,10 +35,12 @@ int main()
|
|||||||
if (msg->type == ix::WebSocketMessageType::Message)
|
if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
{
|
{
|
||||||
std::cout << "received message: " << msg->str << std::endl;
|
std::cout << "received message: " << msg->str << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
else if (msg->type == ix::WebSocketMessageType::Open)
|
else if (msg->type == ix::WebSocketMessageType::Open)
|
||||||
{
|
{
|
||||||
std::cout << "Connection established" << std::endl;
|
std::cout << "Connection established" << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -49,13 +51,16 @@ int main()
|
|||||||
// Send a message to the server (default to TEXT mode)
|
// Send a message to the server (default to TEXT mode)
|
||||||
webSocket.send("hello world");
|
webSocket.send("hello world");
|
||||||
|
|
||||||
while (true)
|
// Display a prompt
|
||||||
{
|
std::cout << "> " << std::flush;
|
||||||
std::string text;
|
|
||||||
std::cout << "> " << std::flush;
|
|
||||||
std::getline(std::cin, text);
|
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
webSocket.send(text);
|
webSocket.send(text);
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -33,11 +33,7 @@ TEST_CASE("dns", "[net]")
|
|||||||
auto dnsLookup = std::make_shared<DNSLookup>("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80);
|
auto dnsLookup = std::make_shared<DNSLookup>("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80);
|
||||||
|
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
struct addrinfo* res = dnsLookup->resolve(errMsg,
|
struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return false; });
|
||||||
[]
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
std::cerr << "Error message: " << errMsg << std::endl;
|
std::cerr << "Error message: " << errMsg << std::endl;
|
||||||
REQUIRE(res == nullptr);
|
REQUIRE(res == nullptr);
|
||||||
}
|
}
|
||||||
@ -48,11 +44,7 @@ TEST_CASE("dns", "[net]")
|
|||||||
|
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
// The callback returning true means we are requesting cancellation
|
// The callback returning true means we are requesting cancellation
|
||||||
struct addrinfo* res = dnsLookup->resolve(errMsg,
|
struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return true; });
|
||||||
[]
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
std::cerr << "Error message: " << errMsg << std::endl;
|
std::cerr << "Error message: " << errMsg << std::endl;
|
||||||
REQUIRE(res == nullptr);
|
REQUIRE(res == nullptr);
|
||||||
}
|
}
|
||||||
|
@ -2378,9 +2378,9 @@ namespace ix
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string readyStateString =
|
std::string readyStateString =
|
||||||
readyState == ReadyState::Connecting
|
readyState == ReadyState::Connecting ? "Connecting"
|
||||||
? "Connecting"
|
: readyState == ReadyState::Closing ? "Closing"
|
||||||
: readyState == ReadyState::Closing ? "Closing" : "Closed";
|
: "Closed";
|
||||||
size_t bufferedAmount = client->bufferedAmount();
|
size_t bufferedAmount = client->bufferedAmount();
|
||||||
|
|
||||||
spdlog::info(
|
spdlog::info(
|
||||||
|
Reference in New Issue
Block a user