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