File examples/blackhole_c.c changed (mode: 100644) (index 50b23f1..a391810) |
25 |
25 |
|
|
26 |
26 |
/* Global variables */ |
/* Global variables */ |
27 |
27 |
static unsigned short debug = 4; |
static unsigned short debug = 4; |
28 |
|
static unsigned int ipv4conns = 0, ipv6conns = 5000; |
|
|
28 |
|
static unsigned int ipv4conns = 1000, ipv6conns = 1000; |
29 |
29 |
|
|
30 |
30 |
static int port = 9000; |
static int port = 9000; |
31 |
31 |
static unsigned int ends = 0; |
static unsigned int ends = 0; |
|
... |
... |
static void c_connected(struct Conn *C) |
40 |
40 |
int amount; |
int amount; |
41 |
41 |
|
|
42 |
42 |
amount = Conn_enqueue(C, buf, buf_size); |
amount = Conn_enqueue(C, buf, buf_size); |
43 |
|
/* old Conn_enqueue returned 0 */ |
|
44 |
|
if ((amount != 0) && (amount != buf_size)) |
|
|
43 |
|
if (amount != buf_size) { |
45 |
44 |
printf("Cannot enqueue whole buffer (%d/%d)!\n", |
printf("Cannot enqueue whole buffer (%d/%d)!\n", |
46 |
45 |
amount, buf_size); |
amount, buf_size); |
47 |
|
bytes += amount; |
|
|
46 |
|
errors++; |
|
47 |
|
} else { |
|
48 |
|
bytes += amount; |
|
49 |
|
} |
48 |
50 |
Conn_close(C); |
Conn_close(C); |
49 |
51 |
} |
} |
50 |
52 |
|
|
51 |
|
static void c_close(struct Conn *C) |
|
52 |
|
{ |
|
53 |
|
} |
|
54 |
|
|
|
55 |
|
static void c_data(struct Conn *C) |
|
56 |
|
{ |
|
57 |
|
} |
|
58 |
|
|
|
59 |
53 |
static void c_error(struct Conn *C) |
static void c_error(struct Conn *C) |
60 |
54 |
{ |
{ |
61 |
55 |
printf("%s id=%llu [%s]\n", |
printf("%s id=%llu [%s]\n", |
|
... |
... |
int main(void) |
69 |
63 |
struct timeval start, end; |
struct timeval start, end; |
70 |
64 |
unsigned int elap; |
unsigned int elap; |
71 |
65 |
unsigned int i; |
unsigned int i; |
72 |
|
struct Conn *C4, *C6; |
|
|
66 |
|
struct Conn *C; |
73 |
67 |
|
|
74 |
68 |
buf_size = 4096; |
buf_size = 4096; |
75 |
69 |
buf = malloc(buf_size); |
buf = malloc(buf_size); |
|
... |
... |
int main(void) |
96 |
90 |
} |
} |
97 |
91 |
|
|
98 |
92 |
Conn_connected_cb = c_connected; |
Conn_connected_cb = c_connected; |
99 |
|
Conn_data_cb = c_data; |
|
100 |
|
Conn_close_cb = c_close; |
|
101 |
93 |
Conn_error_cb = c_error; |
Conn_error_cb = c_error; |
102 |
94 |
|
|
103 |
95 |
gettimeofday(&start, NULL); |
gettimeofday(&start, NULL); |
|
... |
... |
int main(void) |
106 |
98 |
|
|
107 |
99 |
/* ipv4 */ |
/* ipv4 */ |
108 |
100 |
for (i = 0; i < ipv4conns; i++) { |
for (i = 0; i < ipv4conns; i++) { |
109 |
|
C4 = Conn_connect(PF_INET, SOCK_STREAM, "127.0.0.1", port); |
|
110 |
|
if (C4 == NULL) { |
|
111 |
|
printf("Error calling Conn_connect [%s]!\n", |
|
|
101 |
|
C = Conn_alloc(); |
|
102 |
|
if (!C) { |
|
103 |
|
printf("Error alloc Conn struct [%s]!\n", |
112 |
104 |
Conn_strerror()); |
Conn_strerror()); |
113 |
|
return 1; |
|
|
105 |
|
errors++; |
|
106 |
|
} else { |
|
107 |
|
Conn_set_socket_domain(C, PF_INET); |
|
108 |
|
Conn_set_socket_type(C, SOCK_STREAM); |
|
109 |
|
Conn_set_socket_addr(C, "127.0.0.1"); |
|
110 |
|
Conn_set_socket_port(C, port); |
|
111 |
|
ret = Conn_commit(C); |
|
112 |
|
if (ret != 0) { |
|
113 |
|
printf("Error commiting [%s]!\n", |
|
114 |
|
Conn_strerror()); |
|
115 |
|
errors++; |
|
116 |
|
} |
114 |
117 |
} |
} |
115 |
118 |
} |
} |
116 |
119 |
|
|
117 |
120 |
/* ipv6 */ |
/* ipv6 */ |
118 |
121 |
for (i = 0; i < ipv6conns; i++) { |
for (i = 0; i < ipv6conns; i++) { |
119 |
|
C6 = Conn_connect(PF_INET6, SOCK_STREAM, "::1", port); |
|
120 |
|
if (C6 == NULL) { |
|
121 |
|
printf("Error calling Conn_connect6 [%s]!\n", |
|
|
122 |
|
C = Conn_alloc(); |
|
123 |
|
if (!C) { |
|
124 |
|
printf("Error alloc Conn struct [%s]!\n", |
122 |
125 |
Conn_strerror()); |
Conn_strerror()); |
123 |
|
return 1; |
|
|
126 |
|
errors++; |
|
127 |
|
} else { |
|
128 |
|
Conn_set_socket_domain(C, PF_INET6); |
|
129 |
|
Conn_set_socket_type(C, SOCK_STREAM); |
|
130 |
|
Conn_set_socket_addr(C, "::1"); |
|
131 |
|
Conn_set_socket_port(C, port); |
|
132 |
|
ret = Conn_commit(C); |
|
133 |
|
if (ret != 0) { |
|
134 |
|
printf("Error commiting [%s]!\n", |
|
135 |
|
Conn_strerror()); |
|
136 |
|
errors++; |
|
137 |
|
} |
124 |
138 |
} |
} |
125 |
139 |
} |
} |
126 |
140 |
|
|
File examples/blackhole_s.c changed (mode: 100644) (index 3229d7f..78fbbd6) |
25 |
25 |
#include <Conn.h> |
#include <Conn.h> |
26 |
26 |
|
|
27 |
27 |
/* Global variables */ |
/* Global variables */ |
28 |
|
static unsigned short debug = 4; |
|
|
28 |
|
static unsigned short debug = 7; |
29 |
29 |
|
|
30 |
30 |
static int port = 9000; |
static int port = 9000; |
31 |
31 |
static short ipv4 = 1, ipv6 = 1; |
static short ipv4 = 1, ipv6 = 1; |
|
... |
... |
static unsigned long long errors = 0; |
34 |
34 |
|
|
35 |
35 |
static void s_accept_error(struct Conn *C) |
static void s_accept_error(struct Conn *C) |
36 |
36 |
{ |
{ |
37 |
|
printf("Cannot accept a new connection!\n"); |
|
38 |
|
} |
|
39 |
|
|
|
40 |
|
static void s_accept(struct Conn *C) |
|
41 |
|
{ |
|
42 |
|
} |
|
43 |
|
|
|
44 |
|
static void s_close(struct Conn *C) |
|
45 |
|
{ |
|
|
37 |
|
printf("Cannot accept a new connection via %llu!\n", |
|
38 |
|
Conn_getid(C)); |
|
39 |
|
errors++; |
46 |
40 |
} |
} |
47 |
41 |
|
|
48 |
42 |
static void s_data(struct Conn *C) |
static void s_data(struct Conn *C) |
|
... |
... |
static void s_data(struct Conn *C) |
54 |
48 |
|
|
55 |
49 |
static void s_error(struct Conn *C) |
static void s_error(struct Conn *C) |
56 |
50 |
{ |
{ |
57 |
|
/* |
|
58 |
51 |
printf("%s id=%llu (%s)\n", |
printf("%s id=%llu (%s)\n", |
59 |
52 |
__FUNCTION__, Conn_getid(C), Conn_strerror()); |
__FUNCTION__, Conn_getid(C), Conn_strerror()); |
60 |
|
*/ |
|
61 |
53 |
errors++; |
errors++; |
62 |
54 |
} |
} |
63 |
55 |
|
|
64 |
56 |
int main(void) |
int main(void) |
65 |
57 |
{ |
{ |
66 |
|
struct Conn *I4 = NULL, *I6 = NULL; |
|
|
58 |
|
struct Conn *C = NULL; |
67 |
59 |
int ret; |
int ret; |
68 |
60 |
|
|
69 |
61 |
printf("\tPort=%d\n", port); |
printf("\tPort=%d\n", port); |
|
... |
... |
int main(void) |
83 |
75 |
|
|
84 |
76 |
if (ipv4 == 1) { |
if (ipv4 == 1) { |
85 |
77 |
printf("Trying to register IPv4 socket...\n"); |
printf("Trying to register IPv4 socket...\n"); |
86 |
|
I4 = Conn_socket(PF_INET, SOCK_STREAM, port); |
|
87 |
|
if (!I4) |
|
88 |
|
printf("Cannot bind on ipv4 socket [%s].\n", Conn_strerror()); |
|
|
78 |
|
C = Conn_alloc(); |
|
79 |
|
if (!C) { |
|
80 |
|
printf("Cannot alloc socket [%s].\n", Conn_strerror()); |
|
81 |
|
errors++; |
|
82 |
|
} else { |
|
83 |
|
Conn_set_socket_domain(C, PF_INET); |
|
84 |
|
Conn_set_socket_type(C, SOCK_STREAM); |
|
85 |
|
Conn_set_socket_bind_port(C, port); |
|
86 |
|
ret = Conn_commit(C); |
|
87 |
|
if (ret != 0) { |
|
88 |
|
printf("Cannot bind on ipv4 socket [%s].\n", |
|
89 |
|
Conn_strerror()); |
|
90 |
|
errors++; |
|
91 |
|
} |
|
92 |
|
} |
89 |
93 |
} |
} |
90 |
94 |
|
|
91 |
95 |
if (ipv6 == 1) { |
if (ipv6 == 1) { |
92 |
96 |
printf("Trying to register IPv6 socket...\n"); |
printf("Trying to register IPv6 socket...\n"); |
93 |
|
I6 = Conn_socket(PF_INET6, SOCK_STREAM, port); |
|
94 |
|
if (!I6) |
|
95 |
|
printf("Cannot bind on ipv6 socket [%s].\n", Conn_strerror()); |
|
96 |
|
} |
|
97 |
|
|
|
98 |
|
if ((I6 == NULL) && (I4 == NULL)) { |
|
99 |
|
printf("Cannot bind!\n"); |
|
100 |
|
return 1; |
|
|
97 |
|
C = Conn_alloc(); |
|
98 |
|
if (!C) { |
|
99 |
|
printf("Cannot alloc socket [%s].\n", Conn_strerror()); |
|
100 |
|
errors++; |
|
101 |
|
} else { |
|
102 |
|
Conn_set_socket_domain(C, PF_INET6); |
|
103 |
|
Conn_set_socket_type(C, SOCK_STREAM); |
|
104 |
|
Conn_set_socket_bind_port(C, port); |
|
105 |
|
ret = Conn_commit(C); |
|
106 |
|
if (ret != 0) { |
|
107 |
|
printf("Cannot bind on ipv6 socket [%s].\n", |
|
108 |
|
Conn_strerror()); |
|
109 |
|
errors++; |
|
110 |
|
} |
|
111 |
|
} |
101 |
112 |
} |
} |
102 |
113 |
|
|
103 |
|
Conn_accept_cb = s_accept; |
|
104 |
114 |
Conn_data_cb = s_data; |
Conn_data_cb = s_data; |
105 |
|
Conn_close_cb = s_close; |
|
106 |
115 |
Conn_error_cb = s_error; |
Conn_error_cb = s_error; |
107 |
116 |
Conn_accept_error_cb = s_accept_error; |
Conn_accept_error_cb = s_accept_error; |
108 |
117 |
|
|
|
... |
... |
int main(void) |
112 |
121 |
if (ret == -1) { |
if (ret == -1) { |
113 |
122 |
printf("Error calling Conn_poll [%s]!\n", Conn_strerror()); |
printf("Error calling Conn_poll [%s]!\n", Conn_strerror()); |
114 |
123 |
return 1; |
return 1; |
115 |
|
} |
|
|
124 |
|
} else if (ret == 0) |
|
125 |
|
break; |
116 |
126 |
} |
} |
117 |
127 |
|
|
118 |
128 |
printf("Finish. Errors=%llu, Bytes=%llu!\n\n", errors, bytes); |
printf("Finish. Errors=%llu, Bytes=%llu!\n\n", errors, bytes); |