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

Function mio

lib_acl_cpp/samples/udp/server/main.cpp:5–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include "udp_pkt.h"
4
5static void mio(udp_sock& sock, int inter, bool echo)
6{
7#define PKT_CNT 20
8#define BUF_LEN 1024
9
10 udp_pkts upkts(PKT_CNT);
11 int nread = 0, total_read = 0, n = 0, nwrite = 0;
12
13 while (true)
14 {
15 int ret = sock.recv(upkts);
16 if (ret <= 0)
17 {
18 printf("read error %s, ret: %d\r\n",
19 acl::last_serror(), ret);
20 break;
21 }
22
23 nread++;
24 total_read += ret;
25
26 if (echo)
27 {
28 ret = sock.send(upkts);
29 if (ret <= 0)
30 {
31 printf("send error %s, ret: %d\r\n",
32 acl::last_serror(), ret);
33 break;
34 }
35 nwrite++;
36 }
37
38 if (++n % inter == 0) {
39 char buf[256];
40
41 snprintf(buf, sizeof(buf),
42 "curr: %d, total: %d, ret: %d, dlen: %lu, "
43 "nread: %d, nwrite: %d, ip: %s, port: %d",
44 n, total_read, ret,
45 upkts[0]->get_dlen(),
46 nread, nwrite,
47 upkts[0]->get_ip(),
48 upkts[0]->get_port());
49 ACL_METER_TIME(buf);
50 }
51
52 }
53}
54
55int main(void)
56{

Callers 1

mainFunction · 0.70

Calls 6

recvMethod · 0.80
get_dlenMethod · 0.80
last_serrorFunction · 0.50
sendMethod · 0.45
get_ipMethod · 0.45
get_portMethod · 0.45

Tested by

no test coverage detected