File examples/blackhole_c.c changed (mode: 100644) (index 5263dea..306c0b4) |
7 |
7 |
#include <Conn.h> |
#include <Conn.h> |
8 |
8 |
|
|
9 |
9 |
/* Global variables */ |
/* Global variables */ |
10 |
|
static unsigned short debug = 9; |
|
11 |
|
static unsigned int ipv4conns = 1000, ipv6conns = 0; |
|
|
10 |
|
static unsigned short debug = 11; |
|
11 |
|
static unsigned int ipv4conns = 0, ipv6conns = 2; |
12 |
12 |
static int port = 9000; |
static int port = 9000; |
13 |
|
static unsigned int buf_size = 4096 * 10; |
|
|
13 |
|
static unsigned int buf_size = 4096 * 1; |
14 |
14 |
|
|
15 |
15 |
static unsigned int ends = 0; |
static unsigned int ends = 0; |
16 |
16 |
static unsigned char *buf; |
static unsigned char *buf; |
17 |
|
static unsigned long long errors = 0; |
|
|
17 |
|
static unsigned long long alloc_errors = 0; |
|
18 |
|
static unsigned long long commit_errors = 0; |
|
19 |
|
static unsigned long long enqueue_errors = 0; |
|
20 |
|
static unsigned long long conn_errors = 0; |
18 |
21 |
static unsigned long long bytes = 0; |
static unsigned long long bytes = 0; |
19 |
22 |
static unsigned long long latency = 0; |
static unsigned long long latency = 0; |
20 |
23 |
|
|
|
... |
... |
static void c_connected(struct Conn *C) |
27 |
30 |
if (amount == -1) { |
if (amount == -1) { |
28 |
31 |
printf("Cannot enqueue whole buffer (%d/%d)!\n", |
printf("Cannot enqueue whole buffer (%d/%d)!\n", |
29 |
32 |
amount, buf_size); |
amount, buf_size); |
30 |
|
errors++; |
|
|
33 |
|
enqueue_errors++; |
31 |
34 |
} else { |
} else { |
32 |
35 |
bytes += amount; |
bytes += amount; |
33 |
36 |
} |
} |
|
... |
... |
static void c_error(struct Conn *C) |
38 |
41 |
{ |
{ |
39 |
42 |
printf("%s id=%llu [%s]\n", |
printf("%s id=%llu [%s]\n", |
40 |
43 |
__FUNCTION__, Conn_getid(C), Conn_strerror()); |
__FUNCTION__, Conn_getid(C), Conn_strerror()); |
41 |
|
errors++; |
|
|
44 |
|
conn_errors++; |
42 |
45 |
} |
} |
43 |
46 |
|
|
44 |
47 |
static void c_close(struct Conn *C) |
static void c_close(struct Conn *C) |
|
... |
... |
int main(void) |
92 |
95 |
if (!C) { |
if (!C) { |
93 |
96 |
printf("Error alloc Conn struct [%s]!\n", |
printf("Error alloc Conn struct [%s]!\n", |
94 |
97 |
Conn_strerror()); |
Conn_strerror()); |
95 |
|
errors++; |
|
|
98 |
|
alloc_errors++; |
96 |
99 |
} else { |
} else { |
97 |
100 |
Conn_set_socket_domain(C, PF_INET); |
Conn_set_socket_domain(C, PF_INET); |
98 |
101 |
Conn_set_socket_type(C, SOCK_STREAM); |
Conn_set_socket_type(C, SOCK_STREAM); |
|
... |
... |
int main(void) |
102 |
105 |
if (ret != 0) { |
if (ret != 0) { |
103 |
106 |
printf("Error commiting [%s]!\n", |
printf("Error commiting [%s]!\n", |
104 |
107 |
Conn_strerror()); |
Conn_strerror()); |
105 |
|
errors++; |
|
|
108 |
|
commit_errors++; |
106 |
109 |
} |
} |
107 |
110 |
} |
} |
108 |
111 |
} |
} |
|
... |
... |
int main(void) |
113 |
116 |
if (!C) { |
if (!C) { |
114 |
117 |
printf("Error alloc Conn struct [%s]!\n", |
printf("Error alloc Conn struct [%s]!\n", |
115 |
118 |
Conn_strerror()); |
Conn_strerror()); |
116 |
|
errors++; |
|
|
119 |
|
alloc_errors++; |
117 |
120 |
} else { |
} else { |
118 |
121 |
Conn_set_socket_domain(C, PF_INET6); |
Conn_set_socket_domain(C, PF_INET6); |
119 |
122 |
Conn_set_socket_type(C, SOCK_STREAM); |
Conn_set_socket_type(C, SOCK_STREAM); |
|
... |
... |
int main(void) |
123 |
126 |
if (ret != 0) { |
if (ret != 0) { |
124 |
127 |
printf("Error commiting [%s]!\n", |
printf("Error commiting [%s]!\n", |
125 |
128 |
Conn_strerror()); |
Conn_strerror()); |
126 |
|
errors++; |
|
|
129 |
|
commit_errors++; |
127 |
130 |
} |
} |
128 |
131 |
} |
} |
129 |
132 |
} |
} |
|
... |
... |
int main(void) |
136 |
139 |
break; |
break; |
137 |
140 |
} else if (ret == 0) |
} else if (ret == 0) |
138 |
141 |
break; |
break; |
139 |
|
printf("%d event(s), %llu error(s).\n", |
|
140 |
|
ret, errors); |
|
|
142 |
|
printf("%d event(s), Conn_no=%u.\n", |
|
143 |
|
ret, Conn_no); |
141 |
144 |
} |
} |
142 |
145 |
|
|
143 |
146 |
free(buf); |
free(buf); |
|
... |
... |
int main(void) |
147 |
150 |
printf("\n"); |
printf("\n"); |
148 |
151 |
|
|
149 |
152 |
elap = 1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec; |
elap = 1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec; |
150 |
|
printf("Finish in %d.%06d. ipv4conns=%d. ipv6conns=%d. Total=%d. ends=%d" |
|
151 |
|
" Conns per sec = %d, errors = %llu, bytes=%llu" |
|
152 |
|
" latency=%llums" |
|
|
153 |
|
printf("Finish in %d.%06d ipv4conns=%d ipv6conns=%d total=%d ends=%d" |
|
154 |
|
" Conns per sec=%d\n" |
|
155 |
|
"alloc_errors=%llu commit_errors=%llu" |
|
156 |
|
" conn_errors=%llu enqueue_errors=%llu\n" |
|
157 |
|
"bytes=%llu latency=%llums" |
153 |
158 |
"\n", |
"\n", |
154 |
159 |
elap / 1000000, elap % 1000000, |
elap / 1000000, elap % 1000000, |
155 |
160 |
ipv4conns, ipv6conns, ipv4conns + ipv6conns, |
ipv4conns, ipv6conns, ipv4conns + ipv6conns, |
156 |
161 |
ends, (ipv4conns + ipv6conns) / (elap / 1000000 + 1), |
ends, (ipv4conns + ipv6conns) / (elap / 1000000 + 1), |
157 |
|
errors, bytes, latency); |
|
|
162 |
|
alloc_errors, commit_errors, conn_errors, enqueue_errors, |
|
163 |
|
bytes, latency); |
158 |
164 |
|
|
159 |
165 |
Conn_shutdown(); |
Conn_shutdown(); |
160 |
166 |
|
|