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

Function client

example/netcat_timeout.cpp:41–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41task<> client(std::string_view hostname, uint16_t port) {
42 inet_address addr;
43 if (inet_address::resolve(hostname, port, addr)) {
44 Socket sock{Socket::create_tcp(addr.family())};
45 // 连接一个 server
46 int res = co_await sock.connect(addr);
47 if (res < 0) {
48 printf("res=%d: %s\n", res, strerror(-res));
49 }
50 // 生成一个 worker 协程
51 co_spawn(session(std::move(sock)));
52 } else {
53 printf("Unable to resolve %s\n", hostname.data());
54 }
55}
56
57int main(int argc, const char *argv[]) {
58 if (argc < 3) {

Callers 1

mainFunction · 0.70

Calls 4

co_spawnFunction · 0.85
familyMethod · 0.80
connectMethod · 0.80
sessionFunction · 0.70

Tested by

no test coverage detected