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

Function snippetForSocketConnect

Tests/Libraries/Async/AsyncTest.cpp:424–446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

422 // ...do something with new client
423 console.printLine("New client connected!");
424 res.reactivateRequest(true); // We want to receive more clients
425 }
426};
427SC_TRY(accept.start(eventLoop, serverSocket));
428// ... at some later point
429// Stop accepting new clients
430SC_TRY(accept.stop(eventLoop));
431//! [AsyncSocketAcceptSnippet]
432SC_TRY(eventLoop.run());
433return Result(true);
434}
435
436SC::Result snippetForSocketConnect(AsyncEventLoop& eventLoop, Console& console)
437{
438//! [AsyncSocketConnectSnippet]
439// Assuming an already created (and running) AsyncEventLoop named eventLoop
440// ...
441SocketIPAddress localHost;
442SC_TRY(localHost.fromAddressPort("127.0.0.1", 5050)); // Connect to some host and port
443AsyncSocketConnect connect;
444SocketDescriptor client;
445SC_TRY(eventLoop.createAsyncTCPSocket(localHost.getAddressFamily(), client));
446connect.callback = [&](AsyncSocketConnect::Result& res)
447{
448 if (res.isValid())
449 {

Callers

nothing calls this directly

Calls 7

createAsyncTCPSocketMethod · 0.80
getAddressFamilyMethod · 0.80
printLineMethod · 0.80
ResultClass · 0.50
isValidMethod · 0.45
startMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected