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

Function client

example/netcat.cpp:40–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40task<> client(std::string_view hostname, uint16_t port) {
41 inet_address addr;
42 if (inet_address::resolve(hostname, port, addr)) {
43 Socket sock{Socket::create_tcp(addr.family())};
44 // 连接一个 server
45 int res = co_await sock.connect(addr);
46 if (res < 0) {
47 printf("res=%d: %s\n", res, strerror(-res));
48 }
49 // 生成 session 协程
50 co_spawn(recv_session(Socket{sock.fd()}));
51 co_spawn(send_session(Socket{sock.fd()}));
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 6

co_spawnFunction · 0.85
familyMethod · 0.80
connectMethod · 0.80
recv_sessionFunction · 0.70
send_sessionFunction · 0.70
fdMethod · 0.45

Tested by

no test coverage detected