diff options
Diffstat (limited to 'src/util/test_connection_addressing.c')
-rw-r--r-- | src/util/test_connection_addressing.c | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c index c413c18c8..018cf61fb 100644 --- a/src/util/test_connection_addressing.c +++ b/src/util/test_connection_addressing.c | |||
@@ -66,16 +66,15 @@ open_listen_socket () | |||
66 | GNUNET_assert (desc != 0); | 66 | GNUNET_assert (desc != 0); |
67 | if (GNUNET_NETWORK_socket_setsockopt | 67 | if (GNUNET_NETWORK_socket_setsockopt |
68 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 68 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); |
70 | "setsockopt"); | ||
71 | if (GNUNET_OK != | 70 | if (GNUNET_OK != |
72 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, | 71 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, |
73 | sizeof (sa))) | 72 | sizeof (sa))) |
74 | { | 73 | { |
75 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 74 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
76 | "bind"); | 75 | "bind"); |
77 | GNUNET_assert (0); | 76 | GNUNET_assert (0); |
78 | } | 77 | } |
79 | GNUNET_NETWORK_socket_listen (desc, 5); | 78 | GNUNET_NETWORK_socket_listen (desc, 5); |
80 | return desc; | 79 | return desc; |
81 | } | 80 | } |
@@ -83,25 +82,25 @@ open_listen_socket () | |||
83 | 82 | ||
84 | static void | 83 | static void |
85 | receive_check (void *cls, const void *buf, size_t available, | 84 | receive_check (void *cls, const void *buf, size_t available, |
86 | const struct sockaddr *addr, socklen_t addrlen, int errCode) | 85 | const struct sockaddr *addr, socklen_t addrlen, int errCode) |
87 | { | 86 | { |
88 | int *ok = cls; | 87 | int *ok = cls; |
89 | 88 | ||
90 | GNUNET_assert (buf != NULL); /* no timeout */ | 89 | GNUNET_assert (buf != NULL); /* no timeout */ |
91 | if (0 == memcmp (&"Hello World"[sofar], buf, available)) | 90 | if (0 == memcmp (&"Hello World"[sofar], buf, available)) |
92 | sofar += available; | 91 | sofar += available; |
93 | if (sofar < 12) | 92 | if (sofar < 12) |
94 | { | 93 | { |
95 | GNUNET_CONNECTION_receive (asock, 1024, | 94 | GNUNET_CONNECTION_receive (asock, 1024, |
96 | GNUNET_TIME_relative_multiply | 95 | GNUNET_TIME_relative_multiply |
97 | (GNUNET_TIME_UNIT_SECONDS, 5), | 96 | (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, |
98 | &receive_check, cls); | 97 | cls); |
99 | } | 98 | } |
100 | else | 99 | else |
101 | { | 100 | { |
102 | *ok = 0; | 101 | *ok = 0; |
103 | GNUNET_CONNECTION_destroy (asock, GNUNET_YES); | 102 | GNUNET_CONNECTION_destroy (asock, GNUNET_YES); |
104 | } | 103 | } |
105 | } | 104 | } |
106 | 105 | ||
107 | 106 | ||
@@ -117,7 +116,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
117 | GNUNET_assert (asock != NULL); | 116 | GNUNET_assert (asock != NULL); |
118 | GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); | 117 | GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); |
119 | GNUNET_assert (GNUNET_OK == | 118 | GNUNET_assert (GNUNET_OK == |
120 | GNUNET_CONNECTION_get_address (asock, &addr, &alen)); | 119 | GNUNET_CONNECTION_get_address (asock, &addr, &alen)); |
121 | GNUNET_assert (alen == sizeof (struct sockaddr_in)); | 120 | GNUNET_assert (alen == sizeof (struct sockaddr_in)); |
122 | v4 = addr; | 121 | v4 = addr; |
123 | memset (&expect, 0, sizeof (expect)); | 122 | memset (&expect, 0, sizeof (expect)); |
@@ -131,9 +130,9 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
131 | GNUNET_free (addr); | 130 | GNUNET_free (addr); |
132 | GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); | 131 | GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); |
133 | GNUNET_CONNECTION_receive (asock, 1024, | 132 | GNUNET_CONNECTION_receive (asock, 1024, |
134 | GNUNET_TIME_relative_multiply | 133 | GNUNET_TIME_relative_multiply |
135 | (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, | 134 | (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, |
136 | cls); | 135 | cls); |
137 | } | 136 | } |
138 | 137 | ||
139 | static size_t | 138 | static size_t |
@@ -160,17 +159,17 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
160 | v4.sin_port = htons (PORT); | 159 | v4.sin_port = htons (PORT); |
161 | v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | 160 | v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
162 | csock = | 161 | csock = |
163 | GNUNET_CONNECTION_create_from_sockaddr (AF_INET, | 162 | GNUNET_CONNECTION_create_from_sockaddr (AF_INET, |
164 | (const struct sockaddr *) &v4, | 163 | (const struct sockaddr *) &v4, |
165 | sizeof (v4)); | 164 | sizeof (v4)); |
166 | GNUNET_assert (csock != NULL); | 165 | GNUNET_assert (csock != NULL); |
167 | GNUNET_assert (NULL != | 166 | GNUNET_assert (NULL != |
168 | GNUNET_CONNECTION_notify_transmit_ready (csock, 12, | 167 | GNUNET_CONNECTION_notify_transmit_ready (csock, 12, |
169 | GNUNET_TIME_UNIT_SECONDS, | 168 | GNUNET_TIME_UNIT_SECONDS, |
170 | &make_hello, NULL)); | 169 | &make_hello, NULL)); |
171 | GNUNET_CONNECTION_destroy (csock, GNUNET_YES); | 170 | GNUNET_CONNECTION_destroy (csock, GNUNET_YES); |
172 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, | 171 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept, |
173 | &run_accept, cls); | 172 | cls); |
174 | } | 173 | } |
175 | 174 | ||
176 | 175 | ||
@@ -197,11 +196,11 @@ main (int argc, char *argv[]) | |||
197 | 196 | ||
198 | GNUNET_log_setup ("test_connection_addressing", | 197 | GNUNET_log_setup ("test_connection_addressing", |
199 | #if VERBOSE | 198 | #if VERBOSE |
200 | "DEBUG", | 199 | "DEBUG", |
201 | #else | 200 | #else |
202 | "WARNING", | 201 | "WARNING", |
203 | #endif | 202 | #endif |
204 | NULL); | 203 | NULL); |
205 | ret += check (); | 204 | ret += check (); |
206 | return ret; | 205 | return ret; |
207 | } | 206 | } |