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

Function handle_connection

lib_acl_cpp/samples/benchmark/server/main.cpp:4–36  ·  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)
5{
6 acl::string buf;
7 int i = 0;
8
9 struct timeval begin;
10 gettimeofday(&begin, NULL);
11
12 while (true)
13 {
14 if (conn->gets(buf, false) == false)
15 {
16 printf("readline from client over!\r\n");
17 break;
18 }
19 if (conn->write(buf) == -1)
20 {
21 printf("write to client error\r\n");
22 break;
23 }
24
25 if (i % 1000 == 0)
26 printf("read count: %d, readline: %s", i, buf.c_str());
27 i++;
28 }
29
30 struct timeval end;
31 gettimeofday(&end, NULL);
32
33 double n = util::stamp_sub(&end, &begin);
34 printf("total get: %d, spent: %0.2f ms, speed: %0.2f\r\n",
35 i, n, (i * 1000) /(n > 0 ? n : 1));
36}
37
38static void* thread_read(void* ctx)
39{

Callers 1

mainFunction · 0.70

Calls 5

getsMethod · 0.80
gettimeofdayFunction · 0.50
stamp_subFunction · 0.50
writeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…