MCPcopy Create free account
hub / github.com/Codesire-Deng/co_context / server

Function server

example/netcat_timeout.cpp:30–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30task<> server(uint16_t port) {
31 acceptor ac{inet_address{port}};
32 // 限时2s,只接受一个 client
33 int sockfd = co_await timeout(ac.accept(), 2s);
34 if (sockfd >= 0) {
35 co_spawn(session(Socket{sockfd}));
36 } else {
37 log_error(-sockfd);
38 }
39}
40
41task<> client(std::string_view hostname, uint16_t port) {
42 inet_address addr;

Callers 1

mainFunction · 0.70

Calls 5

timeoutFunction · 0.85
co_spawnFunction · 0.85
log_errorFunction · 0.85
acceptMethod · 0.80
sessionFunction · 0.70

Tested by

no test coverage detected