-
Notifications
You must be signed in to change notification settings - Fork 1
/
ws_server.cpp
53 lines (43 loc) · 1.5 KB
/
ws_server.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// This file is part of Poseidon.
// Copyleft 2022 - 2023, LH_Mouse. All wrongs reserved.
#include "../poseidon/precompiled.ipp"
#include "../poseidon/easy/easy_ws_server.hpp"
#include "../poseidon/utils.hpp"
namespace {
using namespace ::poseidon;
extern Easy_WS_Server my_server;
void
event_callback(shptrR<WS_Server_Session> session, Abstract_Fiber& /*fiber*/, WebSocket_Event event, linear_buffer&& data)
{
switch(event) {
case websocket_open:
POSEIDON_LOG_ERROR(("example WS server accepted connection from `$1`: $2"), session->remote_address(), data);
break;
case websocket_text:
POSEIDON_LOG_ERROR(("example WS server received TEXT data: $1"), data);
session->ws_send_text(data);
break;
case websocket_binary:
POSEIDON_LOG_ERROR(("example WS server received BINARY data: $1"), data);
session->ws_send_binary(data);
break;
case websocket_pong:
POSEIDON_LOG_ERROR(("example WS server received PONG data: $1"), data);
break;
case websocket_closed:
POSEIDON_LOG_ERROR(("example WS server shut down connection: $1"), data);
break;
}
}
int
start_server()
{
Socket_Address addr("[::]:3806");
my_server.start(addr);
POSEIDON_LOG_ERROR(("example WS server started: bind = $1"), my_server.local_address());
return 0;
}
// Start the server when this shared library is being loaded.
Easy_WS_Server my_server(event_callback);
int dummy = start_server();
} // namespace