File examples/blackhole_c.c changed (mode: 100644) (index 09a2b10..5263dea) |
7 |
7 |
#include <Conn.h> |
#include <Conn.h> |
8 |
8 |
|
|
9 |
9 |
/* Global variables */ |
/* Global variables */ |
10 |
|
static unsigned short debug = 20; |
|
11 |
|
static unsigned int ipv4conns = 3, ipv6conns = 3; |
|
12 |
|
|
|
|
10 |
|
static unsigned short debug = 9; |
|
11 |
|
static unsigned int ipv4conns = 1000, ipv6conns = 0; |
13 |
12 |
static int port = 9000; |
static int port = 9000; |
|
13 |
|
static unsigned int buf_size = 4096 * 10; |
|
14 |
|
|
14 |
15 |
static unsigned int ends = 0; |
static unsigned int ends = 0; |
15 |
16 |
static unsigned char *buf; |
static unsigned char *buf; |
16 |
|
static int buf_size; |
|
17 |
17 |
static unsigned long long errors = 0; |
static unsigned long long errors = 0; |
18 |
18 |
static unsigned long long bytes = 0; |
static unsigned long long bytes = 0; |
|
19 |
|
static unsigned long long latency = 0; |
19 |
20 |
|
|
20 |
21 |
|
|
21 |
22 |
static void c_connected(struct Conn *C) |
static void c_connected(struct Conn *C) |
|
... |
... |
static void c_error(struct Conn *C) |
40 |
41 |
errors++; |
errors++; |
41 |
42 |
} |
} |
42 |
43 |
|
|
|
44 |
|
static void c_close(struct Conn *C) |
|
45 |
|
{ |
|
46 |
|
latency += Conn_lifetime(C); |
|
47 |
|
} |
|
48 |
|
|
43 |
49 |
int main(void) |
int main(void) |
44 |
50 |
{ |
{ |
45 |
51 |
int ret; |
int ret; |
|
... |
... |
int main(void) |
48 |
54 |
unsigned int i; |
unsigned int i; |
49 |
55 |
struct Conn *C; |
struct Conn *C; |
50 |
56 |
|
|
51 |
|
buf_size = 4096; |
|
52 |
57 |
buf = malloc(buf_size); |
buf = malloc(buf_size); |
53 |
58 |
if (!buf) { |
if (!buf) { |
54 |
59 |
printf("Cannnot alloc %u bytes!\n", buf_size); |
printf("Cannnot alloc %u bytes!\n", buf_size); |
|
... |
... |
int main(void) |
62 |
67 |
printf("Port=%d\n", port); |
printf("Port=%d\n", port); |
63 |
68 |
printf("Debug=%d\n", debug); |
printf("Debug=%d\n", debug); |
64 |
69 |
printf("buf_size=%d\n", buf_size); |
printf("buf_size=%d\n", buf_size); |
|
70 |
|
printf("sys: %s\n", Conn_sys()); |
65 |
71 |
|
|
66 |
72 |
Conn_default_ibuf = 4096; |
Conn_default_ibuf = 4096; |
67 |
73 |
Conn_default_obuf = 4096; |
Conn_default_obuf = 4096; |
|
... |
... |
int main(void) |
74 |
80 |
|
|
75 |
81 |
Conn_connected_cb = c_connected; |
Conn_connected_cb = c_connected; |
76 |
82 |
Conn_error_cb = c_error; |
Conn_error_cb = c_error; |
|
83 |
|
Conn_close_cb = c_close; |
77 |
84 |
|
|
78 |
85 |
gettimeofday(&start, NULL); |
gettimeofday(&start, NULL); |
79 |
86 |
|
|
|
... |
... |
int main(void) |
129 |
136 |
break; |
break; |
130 |
137 |
} else if (ret == 0) |
} else if (ret == 0) |
131 |
138 |
break; |
break; |
|
139 |
|
printf("%d event(s), %llu error(s).\n", |
|
140 |
|
ret, errors); |
132 |
141 |
} |
} |
133 |
142 |
|
|
|
143 |
|
free(buf); |
|
144 |
|
|
134 |
145 |
gettimeofday(&end, NULL); |
gettimeofday(&end, NULL); |
135 |
146 |
|
|
136 |
147 |
printf("\n"); |
printf("\n"); |
137 |
148 |
|
|
138 |
149 |
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; |
139 |
150 |
printf("Finish in %d.%06d. ipv4conns=%d. ipv6conns=%d. Total=%d. ends=%d" |
printf("Finish in %d.%06d. ipv4conns=%d. ipv6conns=%d. Total=%d. ends=%d" |
140 |
|
" Conns per sec = %d, errors = %llu, bytes=%llu\n", |
|
|
151 |
|
" Conns per sec = %d, errors = %llu, bytes=%llu" |
|
152 |
|
" latency=%llums" |
|
153 |
|
"\n", |
141 |
154 |
elap / 1000000, elap % 1000000, |
elap / 1000000, elap % 1000000, |
142 |
155 |
ipv4conns, ipv6conns, ipv4conns + ipv6conns, |
ipv4conns, ipv6conns, ipv4conns + ipv6conns, |
143 |
156 |
ends, (ipv4conns + ipv6conns) / (elap / 1000000 + 1), |
ends, (ipv4conns + ipv6conns) / (elap / 1000000 + 1), |
144 |
|
errors, bytes); |
|
|
157 |
|
errors, bytes, latency); |
145 |
158 |
|
|
146 |
159 |
Conn_shutdown(); |
Conn_shutdown(); |
147 |
160 |
|
|
File examples/blackhole_s.c changed (mode: 100644) (index b253229..33441dd) |
8 |
8 |
#include <Conn.h> |
#include <Conn.h> |
9 |
9 |
|
|
10 |
10 |
/* Global variables */ |
/* Global variables */ |
11 |
|
static unsigned short debug = 20; |
|
12 |
|
|
|
13 |
|
static int port = 9000; |
|
|
11 |
|
static unsigned short debug = 4; |
14 |
12 |
static short ipv4 = 1, ipv6 = 1; |
static short ipv4 = 1, ipv6 = 1; |
|
13 |
|
static int port = 9000; |
|
14 |
|
|
15 |
15 |
static unsigned long long bytes = 0; |
static unsigned long long bytes = 0; |
16 |
16 |
static unsigned long long errors = 0; |
static unsigned long long errors = 0; |
17 |
17 |
|
|
|
18 |
|
|
18 |
19 |
static void s_accept_error(struct Conn *C) |
static void s_accept_error(struct Conn *C) |
19 |
20 |
{ |
{ |
20 |
21 |
printf("Cannot accept a new connection via %llu!\n", |
printf("Cannot accept a new connection via %llu!\n", |
|
... |
... |
int main(void) |
48 |
49 |
printf("\tPort=%d\n", port); |
printf("\tPort=%d\n", port); |
49 |
50 |
printf("\tDebug=%d\n", debug); |
printf("\tDebug=%d\n", debug); |
50 |
51 |
printf("\tipv4=%s ipv6=%s\n", (ipv4 == 1) ? "on" : "off", (ipv6 == 1) ? "on" : "off"); |
printf("\tipv4=%s ipv6=%s\n", (ipv4 == 1) ? "on" : "off", (ipv6 == 1) ? "on" : "off"); |
|
52 |
|
printf("\tsys: %s\n", Conn_sys()); |
51 |
53 |
|
|
52 |
54 |
Conn_default_ibuf = 4096; |
Conn_default_ibuf = 4096; |
53 |
55 |
Conn_default_obuf = 4096; |
Conn_default_obuf = 4096; |
|
... |
... |
int main(void) |
60 |
62 |
return 1; |
return 1; |
61 |
63 |
} |
} |
62 |
64 |
|
|
|
65 |
|
Conn_data_cb = s_data; |
|
66 |
|
Conn_error_cb = s_error; |
|
67 |
|
Conn_accept_error_cb = s_accept_error; |
|
68 |
|
|
63 |
69 |
if (ipv4 == 1) { |
if (ipv4 == 1) { |
64 |
70 |
printf("Trying to register IPv4 socket...\n"); |
printf("Trying to register IPv4 socket...\n"); |
65 |
71 |
C = Conn_alloc(); |
C = Conn_alloc(); |
|
... |
... |
int main(void) |
100 |
106 |
} |
} |
101 |
107 |
} |
} |
102 |
108 |
|
|
103 |
|
Conn_data_cb = s_data; |
|
104 |
|
Conn_error_cb = s_error; |
|
105 |
|
Conn_accept_error_cb = s_accept_error; |
|
106 |
|
|
|
107 |
109 |
while (1) { |
while (1) { |
108 |
110 |
/* -1 we do not have any other business but wait for an event */ |
/* -1 we do not have any other business but wait for an event */ |
109 |
111 |
ret = Conn_poll(-1); |
ret = Conn_poll(-1); |
|
... |
... |
int main(void) |
117 |
119 |
|
|
118 |
120 |
Conn_shutdown(); |
Conn_shutdown(); |
119 |
121 |
|
|
120 |
|
printf("Finish. Errors=%llu, Bytes=%llu!\n\n", errors, bytes); |
|
|
122 |
|
printf("Finish. Errors=%llu, bytes=%llu.\n\n", |
|
123 |
|
errors, bytes); |
121 |
124 |
|
|
122 |
125 |
return 0; |
return 0; |
123 |
126 |
} |
} |