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

Method Start

lib_fiber/samples-gui/SimpleWin/FiberConnect.cpp:13–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11CFiberConnect::~CFiberConnect(void) {}
12
13bool CFiberConnect::Start(void)
14{
15 struct sockaddr_in in;
16 in.sin_family = AF_INET;
17 in.sin_port = htons(port_);
18 if (inet_pton(AF_INET, ip_.c_str(), &in.sin_addr) == -1) {
19 printf("invalid ip = % s\r\n", ip_.c_str());
20 return false;
21 }
22
23 SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
24 if (sock == INVALID_SOCKET) {
25 return false;
26 }
27
28 if (connect(sock, (const sockaddr*)&in, sizeof(in)) == -1) {
29 closesocket(sock);
30 printf("connect %s:%d error\r\n", ip_.c_str(), port_);
31 return false;
32 }
33
34 printf(">>>connect %s:%d ok\r\n", ip_.c_str(), port_);
35
36 const char data[] = "hello world!\r\n";
37 char buf[256];
38 int i;
39 for (i = 0; i < count_; i++) {
40 int ret = send(sock, data, sizeof(data) - 1, 0);
41 if (ret == -1) {
42 break;
43 }
44 ret = recv(sock, buf, sizeof(buf), 0);
45 if (ret <= 0) {
46 break;
47 }
48 if (i % 1000 == 0) {
49 printf(">>>current io=%d, thread=%d, fiber=%d\r\n",
50 i, GetCurrentThreadId(), acl::fiber::self());
51 }
52 }
53
54 closesocket(sock);
55 printf(">>>All over count=%d, %d\r\n", count_, i);
56 return true;
57}

Callers 1

WndProcFunction · 0.80

Calls 7

inet_ptonFunction · 0.85
socketFunction · 0.50
connectFunction · 0.50
sendFunction · 0.50
recvFunction · 0.50
selfFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected