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

Function handle_connection

lib_acl_cpp/samples/benchmark/client2/main.cpp:7–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5static int __len = 1024;
6
7static void handle_connection(acl::socket_stream& conn)
8{
9 acl::string wbuf(__len + 1);
10 char* buf = (char*) malloc(__len + 1);
11
12 int i;
13
14 for (i = 0; i < __len; i++)
15 wbuf += 'X';
16
17 struct timeval begin;
18 gettimeofday(&begin, NULL);
19
20 for (i = 0; i < __max; i++)
21 {
22 if (conn.write(wbuf) == -1)
23 {
24 printf("write to server error\r\n");
25 break;
26 }
27
28 if (conn.read(buf, __len, true) == -1)
29 {
30 printf("readline from server error\r\n");
31 break;
32 }
33
34 if (i <= 1)
35 {
36 buf[__len] = 0;
37 printf("buf: %s\r\n", buf);
38 }
39
40 if (i % 1000 == 0)
41 {
42 char tmp[64];
43 snprintf(tmp, sizeof(tmp), "total: %d, curr: %d, len: %d",
44 __max, i, __len);
45 ACL_METER_TIME(tmp);
46 }
47 }
48
49 free(buf);
50
51 struct timeval end;
52 gettimeofday(&end, NULL);
53
54 double n = util::stamp_sub(&end, &begin);
55 printf("total get: %d, spent: %0.2f ms, speed: %0.2f\r\n",
56 __max, n, (i * 1000) /(n > 0 ? n : 1));
57}
58
59static void usage(const char* procname)
60{

Callers 1

mainFunction · 0.70

Calls 6

mallocFunction · 0.85
freeFunction · 0.85
gettimeofdayFunction · 0.50
stamp_subFunction · 0.50
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…