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

Function handle_connection

lib_acl_cpp/samples/benchmark/server2/main.cpp:4–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "util.h"
3
4static void handle_connection(acl::socket_stream* conn, int len, int step)
5{
6 char* buf = (char*) malloc(len + 1), *ptr;
7 int i = 0, ret;
8
9 len = (len / step) * step;
10 if (len == 0)
11 {
12 printf("len: %d too small, step: %d\r\n", len, step);
13 return;
14 }
15
16 struct timeval begin;
17 gettimeofday(&begin, NULL);
18
19 while (true)
20 {
21 ptr = buf;
22 for (int j = 0; j < len; j += step)
23 {
24 ret = conn->read(ptr, step, true);
25 if (ret == -1)
26 {
27 printf("readline from client over!\r\n");
28 goto END;
29 }
30
31 ptr += ret;
32 }
33
34 if (i <= 1)
35 {
36 *ptr = 0;
37 printf("buf: %s\r\n", buf);
38 }
39
40 if (conn->write(buf, len) == -1)
41 {
42 printf("write to client error\r\n");
43 break;
44 }
45
46 buf[0] = 0;
47 i++;
48 }
49
50END:
51 free(buf);
52
53 struct timeval end;
54 gettimeofday(&end, NULL);
55
56 double n = util::stamp_sub(&end, &begin);
57 printf("total get: %d, spent: %0.2f ms, speed: %0.2f\r\n",
58 i, n, (i * 1000) /(n > 0 ? n : 1));
59}
60
61static void usage(const char* procname)

Callers 1

mainFunction · 0.70

Calls 6

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…