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

Function run

lib_acl_cpp/samples/udp_client/main.cpp:10–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8static bool __server_fixed = true;
9
10static void run(void)
11{
12 acl::socket_stream stream;
13 char* buf;
14
15 // �󶨱��ص�ַ
16 if (stream.bind_udp(__local_addr) == false)
17 {
18 printf("bind addr %s error %s\r\n",
19 __server_addr, acl::last_serror());
20 return;
21 }
22
23 // ����Զ�̷����ַ
24 else
25 stream.set_peer(__server_addr);
26
27 stream.set_rw_timeout(1);
28
29 // �����ڴ�
30 buf = (char*) malloc(__dat_length + 1);
31 memset(buf, 'X', __dat_length);
32 buf[__dat_length] = 0;
33
34 char res[4096];
35
36 struct timeval begin;
37 gettimeofday(&begin, NULL);
38
39 int i = 0, ret;
40 for (; i < __max_count; i++)
41 {
42 // ����˿��ܻ��ñ�ĵ�ַ�ظ����ݣ�������Ҫ��������Զ�̷����ַ
43 if (!__server_fixed)
44 stream.set_peer(__server_addr);
45
46 // ��������
47 if (stream.write(buf, __dat_length) == -1)
48 {
49 printf("write error %s\r\n", acl::last_serror());
50 break;
51 }
52
53 // ��������
54 else if ((ret = stream.read(res, sizeof(res) - 1, false)) == -1)
55 {
56 printf("read error %s\r\n", acl::last_serror());
57 break;
58 }
59
60 if (i % 1000 == 0)
61 {
62 res[ret] = 0;
63 printf("read >>> %s\r\n", res);
64 }
65
66 if (i % 1000 == 0)
67 {

Callers 1

mainFunction · 0.70

Calls 10

mallocFunction · 0.85
freeFunction · 0.85
bind_udpMethod · 0.80
set_rw_timeoutMethod · 0.80
last_serrorFunction · 0.50
gettimeofdayFunction · 0.50
stamp_subFunction · 0.50
set_peerMethod · 0.45
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected