Skip to content

Commit e78019d

Browse files
committed
(ws) port ws transfer to the new server API
1 parent 0f026c5 commit e78019d

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

docs/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All changes to this project will be documented in this file.
33

4+
## [9.10.3] - 2020-07-24
5+
6+
(ws) port ws transfer to the new server API
7+
48
## [9.10.2] - 2020-07-24
59

610
(websocket client) reset WebSocketTransport onClose callback in the WebSocket destructor

ixwebsocket/IXWebSocketVersion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
#pragma once
88

9-
#define IX_WEBSOCKET_VERSION "9.10.2"
9+
#define IX_WEBSOCKET_VERSION "9.10.3"

makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ install_cmake_for_linux:
238238
doc:
239239
mkdocs gh-deploy
240240

241-
change:
241+
change: format
242242
vim ixwebsocket/IXWebSocketVersion.h docs/CHANGELOG.md
243243

244244
.PHONY: test

ws/ws_transfer.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ namespace ix
1919
ix::WebSocketServer server(port, hostname);
2020
server.setTLSOptions(tlsOptions);
2121

22-
server.setOnConnectionCallback([&server](std::shared_ptr<ix::WebSocket> webSocket,
23-
std::shared_ptr<ConnectionState> connectionState,
24-
std::unique_ptr<ConnectionInfo> connectionInfo) {
25-
auto remoteIp = connectionInfo->remoteIp;
26-
webSocket->setOnMessageCallback([webSocket, connectionState, remoteIp, &server](
27-
const WebSocketMessagePtr& msg) {
22+
server.setOnClientMessageCallback(
23+
[&server](std::shared_ptr<ConnectionState> connectionState,
24+
ConnectionInfo& connectionInfo,
25+
WebSocket& webSocket,
26+
const WebSocketMessagePtr& msg) {
27+
auto remoteIp = connectionInfo.remoteIp;
2828
if (msg->type == ix::WebSocketMessageType::Open)
2929
{
3030
spdlog::info("ws_transfer: New connection");
@@ -43,7 +43,7 @@ namespace ix
4343
connectionState->getId(),
4444
msg->closeInfo.code,
4545
msg->closeInfo.reason);
46-
auto remaining = server.getClients().erase(webSocket);
46+
auto remaining = server.getClients().size() - 1;
4747
spdlog::info("ws_transfer: {} remaining clients", remaining);
4848
}
4949
else if (msg->type == ix::WebSocketMessageType::Error)
@@ -65,7 +65,7 @@ namespace ix
6565
size_t receivers = 0;
6666
for (auto&& client : server.getClients())
6767
{
68-
if (client != webSocket)
68+
if (client.get() != &webSocket)
6969
{
7070
auto readyState = client->getReadyState();
7171
auto id = connectionState->getId();
@@ -119,7 +119,6 @@ namespace ix
119119
}
120120
}
121121
});
122-
});
123122

124123
auto res = server.listen();
125124
if (!res.first)

0 commit comments

Comments
 (0)