MCPcopy Create free account
hub / github.com/acl-dev/acl / run

Method run

lib_acl_cpp/samples/connect/main.cpp:14–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13protected:
14 void* run(void)
15 {
16 acl::socket_stream conn;
17 if (!conn.open(addr_, 10, 10)) {
18 printf("%ld: connect %s error %s\r\n",
19 acl::thread::self(), addr_.c_str(),
20 acl::last_serror());
21 return NULL;
22 }
23
24 (void) conn.set_tcp_solinger(true, 0);
25
26 printf("connect %s ok, my addr=%s\r\n",
27 addr_.c_str(), conn.get_local(true));
28 for (int i = 0; i < n_; i++) {
29 if (conn.format("thread-%ld: hello world\r\n",
30 acl::thread::self()) == -1) {
31
32 printf("write to %s error %s\r\n",
33 addr_.c_str(), acl::last_serror());
34 break;
35 }
36 acl::string buf;
37 if (!conn.gets(buf)) {
38 printf("gets from %s error %s\r\n",
39 addr_.c_str(), acl::last_serror());
40 break;
41 } else {
42 printf("%ld: %s\r\n", acl::thread::self(),
43 buf.c_str());
44 }
45 }
46
47 printf("sleep 2 seconds\r\n");
48 sleep(2);
49 printf("disconnect from %s now\r\n", addr_.c_str());
50 return NULL;
51 }
52
53private:
54 acl::string addr_;

Callers

nothing calls this directly

Calls 8

getsMethod · 0.80
selfFunction · 0.50
last_serrorFunction · 0.50
sleepFunction · 0.50
openMethod · 0.45
c_strMethod · 0.45
get_localMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected