-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.cpp
More file actions
140 lines (119 loc) · 6.47 KB
/
Copy pathserver.cpp
File metadata and controls
140 lines (119 loc) · 6.47 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "ServerContext.h" // IWYU pragma: keep
#include <SemanticLog.h>
#include <core/SNodeC.h>
#include <net/in/stream/legacy/SocketServer.h>
#include <net/in/stream/tls/SocketServer.h>
#include <net/in6/stream/legacy/SocketServer.h>
#include <net/un/stream/legacy/SocketServer.h>
int main(int argc, char* argv[]) {
core::SNodeC::init(argc, argv);
using Server = net::in::stream::legacy::SocketServer<ServerContextFactory>;
using SocketConnection = net::in::stream::legacy::SocketServer<ServerContextFactory>::SocketConnection;
Server server(
[](SocketConnection* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});
server.listen(8080, 5, [](const Server::SocketAddress& socketAddress, int errnum) -> void {
if (errnum < 0) {
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError";
} else if (errnum > 0) {
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum)
<< "OnError: " << socketAddress.toString();
} else {
snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString();
}
});
using ServerTLS = net::in::stream::tls::SocketServer<ServerContextFactory>;
using SocketConnectionTLS = net::in::stream::tls::SocketServer<ServerContextFactory>::SocketConnection;
ServerTLS servertls(
[](SocketConnectionTLS* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionTLS* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionTLS* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});
servertls.getConfig()
.setCertChain("/home/voc/projects/ServerClient/WebServerCertificateChain.pem")
.setCertKey("/home/voc/projects/ServerClient/Volker_Christian_-_WEB-Cert.pem")
.setCertKeyPassword("pentium5")
.setCaCertFile("/home/voc/projects/ServerClient/Client-Root-CA.crt");
servertls.listen(8082, 5, [](const ServerTLS::SocketAddress& socketAddress, int errnum) -> void {
if (errnum < 0) {
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError";
} else if (errnum > 0) {
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum)
<< "OnError: " << socketAddress.toString();
} else {
snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString();
}
});
using Server6 = net::in6::stream::legacy::SocketServer<ServerContextFactory>;
using SocketConnection6 = net::in6::stream::legacy::SocketServer<ServerContextFactory>::SocketConnection;
Server6 server6(
[](SocketConnection6* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection6* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection6* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});
server6.listen(8081, 5, [](const Server6::SocketAddress& socketAddress, core::socket::State errnum) -> void {
if (errnum < 0) {
snode::semantic::sysError(
snode::semantic::appLog(), logger::LogLevel::Error, static_cast<int>(errnum))
<< "OnError";
} else if (errnum > 0) {
snode::semantic::sysError(
snode::semantic::appLog(), logger::LogLevel::Error, static_cast<int>(errnum))
<< "OnError: " << socketAddress.toString();
} else {
snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString();
}
});
using ServerUn = net::un::stream::legacy::SocketServer<ServerContextFactory>;
using SocketConnectionUn = net::un::stream::legacy::SocketServer<ServerContextFactory>::SocketConnection;
ServerUn serverUn(
[](SocketConnectionUn* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionUn* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionUn* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});
serverUn.listen("/tmp/testsocket", 5, [](const ServerUn::SocketAddress& socketAddress, core::socket::State errnum) -> void {
if (errnum < 0) {
snode::semantic::sysError(
snode::semantic::appLog(), logger::LogLevel::Error, static_cast<int>(errnum))
<< "OnError";
} else if (errnum > 0) {
snode::semantic::sysError(
snode::semantic::appLog(), logger::LogLevel::Error, static_cast<int>(errnum))
<< "OnError: " << socketAddress.toString();
} else {
snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString();
}
});
/*
sighandler_t oldSigIntHandler = core::system::signal(SIGINT, stoponsig);
do {
core::SNodeC::tick(10);
} while (!stop);
core::SNodeC::free();
core::system::signal(SIGINT, oldSigIntHandler);
return 0;
*/
return core::SNodeC::start();
}