MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / createServer

Function createServer

Examples/AwaitFileCourier/AwaitFileCourier.cpp:22–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20namespace SC
21{
22static Result createServer(AsyncEventLoop& eventLoop, SocketDescriptor& serverSocket, SocketIPAddress& address)
23{
24 constexpr uint16_t firstPort = 39171;
25 constexpr uint16_t numPorts = 64;
26
27 Result lastError = Result::Error("Could not bind AwaitFileCourier socket");
28 for (uint16_t offset = 0; offset < numPorts; ++offset)
29 {
30 const uint16_t port = static_cast<uint16_t>(firstPort + offset);
31 SC_TRY(address.fromAddressPort("127.0.0.1", port));
32
33 SocketDescriptor candidate;
34 SC_TRY(eventLoop.createAsyncTCPSocket(address.getAddressFamily(), candidate));
35
36 SocketServer server(candidate);
37 lastError = server.bind(address);
38 if (lastError)
39 {
40 SC_TRY(server.listen(1));
41 return Result::Explicit(serverSocket.assign(move(candidate)));
42 }
43 }
44 return lastError;
45}
46
47static Result createSocketPair(AsyncEventLoop& eventLoop, SocketDescriptor& sender, SocketDescriptor& receiver)
48{

Callers 1

createSocketPairFunction · 0.70

Calls 5

createAsyncTCPSocketMethod · 0.80
getAddressFamilyMethod · 0.80
ErrorEnum · 0.50
bindMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected