diff options
author | Nils Durner <durner@gnunet.org> | 2009-08-30 21:06:23 +0000 |
---|---|---|
committer | Nils Durner <durner@gnunet.org> | 2009-08-30 21:06:23 +0000 |
commit | a095a849fcd95efeb57db80b4346e4f2eedf9899 (patch) | |
tree | 07a94b227de9f37927d3aed7cc417821f80ddec1 | |
parent | d986f2c7460120ffc3f199b29a06126d0b97b75b (diff) | |
download | gnunet-a095a849fcd95efeb57db80b4346e4f2eedf9899.tar.gz gnunet-a095a849fcd95efeb57db80b4346e4f2eedf9899.zip |
docs & GNUnet-style return codes
-rw-r--r-- | src/include/gnunet_network_lib.h | 170 | ||||
-rw-r--r-- | src/util/connection.c | 24 | ||||
-rw-r--r-- | src/util/network.c | 192 | ||||
-rw-r--r-- | src/util/server.c | 10 | ||||
-rw-r--r-- | src/util/service.c | 2 | ||||
-rw-r--r-- | src/util/test_connection.c | 2 | ||||
-rw-r--r-- | src/util/test_connection_addressing.c | 2 | ||||
-rw-r--r-- | src/util/test_connection_receive_cancel.c | 2 | ||||
-rw-r--r-- | src/util/test_connection_timeout.c | 2 | ||||
-rw-r--r-- | src/util/test_service.c | 2 |
10 files changed, 350 insertions, 58 deletions
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index b475ff4f0..97fcf2618 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h | |||
@@ -51,93 +51,243 @@ struct GNUNET_NETWORK_FDSet; | |||
51 | #include "gnunet_disk_lib.h" | 51 | #include "gnunet_disk_lib.h" |
52 | #include "gnunet_time_lib.h" | 52 | #include "gnunet_time_lib.h" |
53 | 53 | ||
54 | 54 | /** | |
55 | * accept a new connection on a socket | ||
56 | * | ||
57 | * @param desc bound socket | ||
58 | * @param address address of the connecting peer, may be NULL | ||
59 | * @param address_len length of address | ||
60 | * @return client socket | ||
61 | */ | ||
55 | struct GNUNET_NETWORK_Handle * | 62 | struct GNUNET_NETWORK_Handle * |
56 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | 63 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, |
57 | struct sockaddr *address, | 64 | struct sockaddr *address, |
58 | socklen_t *address_len); | 65 | socklen_t *address_len); |
59 | 66 | ||
67 | /** | ||
68 | * Make a non-inheritable to child processes | ||
69 | * @param socket | ||
70 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
71 | * @warning Not implemented on Windows | ||
72 | */ | ||
60 | int | 73 | int |
61 | GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle | 74 | GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle |
62 | *desc); | 75 | *desc); |
63 | 76 | ||
64 | 77 | /** | |
78 | * Bind to a connected socket | ||
79 | * @param desc socket | ||
80 | * @param address address to be bound | ||
81 | * @param address_len length of address | ||
82 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
83 | */ | ||
65 | int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | 84 | int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, |
66 | const struct sockaddr *address, socklen_t address_len); | 85 | const struct sockaddr *address, socklen_t address_len); |
67 | 86 | ||
87 | /** | ||
88 | * Close a socket | ||
89 | * @param desc socket | ||
90 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
91 | */ | ||
68 | int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc); | 92 | int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc); |
69 | 93 | ||
94 | /** | ||
95 | * Connect a socket | ||
96 | * @param desc socket | ||
97 | * @param address peer address | ||
98 | * @param length of address | ||
99 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
100 | */ | ||
70 | int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | 101 | int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, |
71 | const struct sockaddr *address, socklen_t address_len); | 102 | const struct sockaddr *address, socklen_t address_len); |
72 | 103 | ||
104 | /** | ||
105 | * Get socket options | ||
106 | * @param desc socket | ||
107 | * @param level protocol level of the option | ||
108 | * @param optname identifier of the option | ||
109 | * @param optval options | ||
110 | * @param optlen length of optval | ||
111 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
112 | */ | ||
73 | int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname, | 113 | int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname, |
74 | void *optval, socklen_t *optlen); | 114 | void *optval, socklen_t *optlen); |
75 | 115 | ||
116 | /** | ||
117 | * Listen on a socket | ||
118 | * @param desc socket | ||
119 | * @param backlog length of the listen queue | ||
120 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
121 | */ | ||
76 | int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog); | 122 | int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog); |
77 | 123 | ||
78 | ssize_t GNUNET_NETWORK_socket_read (const struct GNUNET_NETWORK_Handle *desc, void *buf, | 124 | /** |
79 | size_t nbyte); | 125 | * Read data from a connected socket |
80 | 126 | * @param desc socket | |
127 | * @param buffer buffer | ||
128 | * @param length length of buffer | ||
129 | * @param flags type of message reception | ||
130 | */ | ||
81 | ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, void *buffer, | 131 | ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, void *buffer, |
82 | size_t length, int flags); | 132 | size_t length, int flags); |
83 | 133 | ||
134 | /** | ||
135 | * Check if sockets meet certain conditions | ||
136 | * @param rfds set of sockets to be checked for readability | ||
137 | * @param wfds set of sockets to be checked for writability | ||
138 | * @param efds set of sockets to be checked for exceptions | ||
139 | * @param timeout relative value when to return | ||
140 | * @return number of selected sockets, GNUNET_SYSERR on error | ||
141 | */ | ||
84 | int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | 142 | int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, |
85 | struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds, | 143 | struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds, |
86 | struct GNUNET_TIME_Relative timeout); | 144 | struct GNUNET_TIME_Relative timeout); |
87 | 145 | ||
88 | /** | 146 | /** |
89 | * Set if a socket should use blocking or non-blocking IO. | 147 | * Set if a socket should use blocking or non-blocking IO. |
90 | * | 148 | * @param fd socket |
149 | * @param doBlock blocking mode | ||
91 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 150 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
92 | */ | 151 | */ |
93 | int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock); | 152 | int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock); |
94 | 153 | ||
154 | /** | ||
155 | * Send data | ||
156 | * @param desc socket | ||
157 | * @param buffer data to send | ||
158 | * @param length size of the buffer | ||
159 | * @param flags type of message transmission | ||
160 | * @return number of bytes sent, GNUNET_SYSERR on error | ||
161 | */ | ||
95 | ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc, | 162 | ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc, |
96 | const void *buffer, size_t length, int flags); | 163 | const void *buffer, size_t length, int flags); |
97 | 164 | ||
165 | /** | ||
166 | * Send data | ||
167 | * @param desc socket | ||
168 | * @param message data to send | ||
169 | * @param length size of the data | ||
170 | * @param flags type of message transmission | ||
171 | * @param dest_addr destination address | ||
172 | * @param dest_len length of address | ||
173 | * @return number of bytes sent, GNUNET_SYSERR on error | ||
174 | */ | ||
98 | ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc, | 175 | ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc, |
99 | const void *message, size_t length, int flags, | 176 | const void *message, size_t length, int flags, |
100 | const struct sockaddr *dest_addr, | 177 | const struct sockaddr *dest_addr, |
101 | socklen_t dest_len); | 178 | socklen_t dest_len); |
102 | 179 | ||
180 | /** | ||
181 | * Set socket option | ||
182 | * @param fd socket | ||
183 | * @param level protocol level of the option | ||
184 | * @param option_name option identifier | ||
185 | * @param option_value value to set | ||
186 | * @param option_len size of option_value | ||
187 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
188 | */ | ||
103 | int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, | 189 | int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, |
104 | const void *option_value, socklen_t option_len); | 190 | const void *option_value, socklen_t option_len); |
105 | 191 | ||
192 | /** | ||
193 | * Shut down socket operations | ||
194 | * @param desc socket | ||
195 | * @param how type of shutdown | ||
196 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
197 | */ | ||
106 | int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how); | 198 | int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how); |
107 | 199 | ||
200 | /** | ||
201 | * Create a new socket | ||
202 | * @param domain domain of the socket | ||
203 | * @param type socket type | ||
204 | * @param protocol network protocol | ||
205 | * @return new socket, NULL on error | ||
206 | */ | ||
108 | struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol); | 207 | struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol); |
109 | 208 | ||
110 | ssize_t GNUNET_NETWORK_socket_write (const struct GNUNET_NETWORK_Handle *desc, | 209 | /** |
111 | const void *buf, size_t nbyte); | 210 | * Reset FD set |
112 | 211 | * @param fds fd set | |
113 | 212 | */ | |
114 | void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds); | 213 | void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds); |
115 | 214 | ||
215 | /** | ||
216 | * Add a socket to the FD set | ||
217 | * @param fds fd set | ||
218 | * @param desc socket to add | ||
219 | */ | ||
116 | void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, | 220 | void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, |
117 | const struct GNUNET_NETWORK_Handle *desc); | 221 | const struct GNUNET_NETWORK_Handle *desc); |
118 | 222 | ||
223 | /** | ||
224 | * Check whether a socket is part of the fd set | ||
225 | * @param fds fd set | ||
226 | * @param desc socket | ||
227 | */ | ||
119 | int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, | 228 | int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, |
120 | const struct GNUNET_NETWORK_Handle *desc); | 229 | const struct GNUNET_NETWORK_Handle *desc); |
121 | 230 | ||
231 | /** | ||
232 | * Add one fd set to another | ||
233 | * @param dst the fd set to add to | ||
234 | * @param src the fd set to add from | ||
235 | */ | ||
122 | void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, | 236 | void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, |
123 | const struct GNUNET_NETWORK_FDSet *src); | 237 | const struct GNUNET_NETWORK_FDSet *src); |
124 | 238 | ||
239 | /** | ||
240 | * Copy one fd set to another | ||
241 | * @param to destination | ||
242 | * @param from source | ||
243 | */ | ||
125 | void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to, | 244 | void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to, |
126 | const struct GNUNET_NETWORK_FDSet *from); | 245 | const struct GNUNET_NETWORK_FDSet *from); |
127 | 246 | ||
247 | /** | ||
248 | * Copy a native fd set | ||
249 | * @param to destination | ||
250 | * @param from native source set | ||
251 | * @param the biggest socket number in from + 1 | ||
252 | */ | ||
128 | void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from, | 253 | void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from, |
129 | int nfds); | 254 | int nfds); |
130 | 255 | ||
256 | /** | ||
257 | * Add a file handle to the fd set | ||
258 | * @param fds fd set | ||
259 | * @param h the file handle to add | ||
260 | */ | ||
131 | void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, | 261 | void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, |
132 | const struct GNUNET_DISK_FileHandle *h); | 262 | const struct GNUNET_DISK_FileHandle *h); |
133 | 263 | ||
264 | /** | ||
265 | * Check if a file handle is part of an fd set | ||
266 | * @param fds fd set | ||
267 | * @param h file handle | ||
268 | * @return GNUNET_YES if the file handle is part of the set | ||
269 | */ | ||
134 | int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, | 270 | int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, |
135 | const struct GNUNET_DISK_FileHandle *h); | 271 | const struct GNUNET_DISK_FileHandle *h); |
136 | 272 | ||
273 | /** | ||
274 | * Checks if two fd sets overlap | ||
275 | * @param fds1 first fd set | ||
276 | * @param fds2 second fd set | ||
277 | * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise | ||
278 | */ | ||
137 | int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2); | 279 | int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2); |
138 | 280 | ||
281 | /** | ||
282 | * Creates an fd set | ||
283 | * @return a new fd set | ||
284 | */ | ||
139 | struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create (void); | 285 | struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create (void); |
140 | 286 | ||
287 | /** | ||
288 | * Releases the associated memory of an fd set | ||
289 | * @param fds fd set | ||
290 | */ | ||
141 | void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds); | 291 | void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds); |
142 | 292 | ||
143 | 293 | ||
diff --git a/src/util/connection.c b/src/util/connection.c index 9ae72b2dc..2e3a64370 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -276,7 +276,7 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle | |||
276 | if (addrlen > sizeof (addr)) | 276 | if (addrlen > sizeof (addr)) |
277 | { | 277 | { |
278 | GNUNET_break (0); | 278 | GNUNET_break (0); |
279 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock)); | 279 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
280 | return NULL; | 280 | return NULL; |
281 | } | 281 | } |
282 | 282 | ||
@@ -310,7 +310,7 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle | |||
310 | _("Access denied to `%s'\n"), | 310 | _("Access denied to `%s'\n"), |
311 | GNUNET_a2s(uaddr, addrlen)); | 311 | GNUNET_a2s(uaddr, addrlen)); |
312 | GNUNET_break (0 == GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); | 312 | GNUNET_break (0 == GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); |
313 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock)); | 313 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
314 | GNUNET_free (uaddr); | 314 | GNUNET_free (uaddr); |
315 | return NULL; | 315 | return NULL; |
316 | } | 316 | } |
@@ -436,7 +436,7 @@ try_connect (struct GNUNET_CONNECTION_Handle *sock) | |||
436 | if (GNUNET_SYSERR == GNUNET_NETWORK_socket_set_blocking (s, GNUNET_NO)) | 436 | if (GNUNET_SYSERR == GNUNET_NETWORK_socket_set_blocking (s, GNUNET_NO)) |
437 | { | 437 | { |
438 | /* we'll treat this one as fatal */ | 438 | /* we'll treat this one as fatal */ |
439 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); | 439 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
440 | return GNUNET_SYSERR; | 440 | return GNUNET_SYSERR; |
441 | } | 441 | } |
442 | #if DEBUG_CONNECTION | 442 | #if DEBUG_CONNECTION |
@@ -445,13 +445,13 @@ try_connect (struct GNUNET_CONNECTION_Handle *sock) | |||
445 | GNUNET_a2s(sock->ai_pos->ai_addr, | 445 | GNUNET_a2s(sock->ai_pos->ai_addr, |
446 | sock->ai_pos->ai_addrlen)); | 446 | sock->ai_pos->ai_addrlen)); |
447 | #endif | 447 | #endif |
448 | if ((0 != GNUNET_NETWORK_socket_connect (s, | 448 | if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, |
449 | sock->ai_pos->ai_addr, | 449 | sock->ai_pos->ai_addr, |
450 | sock->ai_pos->ai_addrlen)) && (errno != EINPROGRESS)) | 450 | sock->ai_pos->ai_addrlen)) && (errno != EINPROGRESS)) |
451 | { | 451 | { |
452 | /* maybe refused / unsupported address, try next */ | 452 | /* maybe refused / unsupported address, try next */ |
453 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); | 453 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); |
454 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); | 454 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
455 | sock->ai_pos = sock->ai_pos->ai_next; | 455 | sock->ai_pos = sock->ai_pos->ai_next; |
456 | continue; | 456 | continue; |
457 | } | 457 | } |
@@ -497,7 +497,7 @@ connect_continuation (void *cls, | |||
497 | GNUNET_a2s(sock->addr, sock->addrlen)); | 497 | GNUNET_a2s(sock->addr, sock->addrlen)); |
498 | #endif | 498 | #endif |
499 | /* connect failed / timed out */ | 499 | /* connect failed / timed out */ |
500 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock->sock)); | 500 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); |
501 | sock->sock = NULL; | 501 | sock->sock = NULL; |
502 | if (GNUNET_SYSERR == try_connect (sock)) | 502 | if (GNUNET_SYSERR == try_connect (sock)) |
503 | { | 503 | { |
@@ -619,7 +619,7 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle | |||
619 | if (GNUNET_SYSERR == GNUNET_NETWORK_socket_set_blocking (s, GNUNET_NO)) | 619 | if (GNUNET_SYSERR == GNUNET_NETWORK_socket_set_blocking (s, GNUNET_NO)) |
620 | { | 620 | { |
621 | /* we'll treat this one as fatal */ | 621 | /* we'll treat this one as fatal */ |
622 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); | 622 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
623 | return NULL; | 623 | return NULL; |
624 | } | 624 | } |
625 | #if DEBUG_CONNECTION | 625 | #if DEBUG_CONNECTION |
@@ -627,11 +627,11 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle | |||
627 | _("Trying to connect to `%s'\n"), | 627 | _("Trying to connect to `%s'\n"), |
628 | GNUNET_a2s(serv_addr, addrlen)); | 628 | GNUNET_a2s(serv_addr, addrlen)); |
629 | #endif | 629 | #endif |
630 | if ((0 != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && (errno != EINPROGRESS)) | 630 | if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && (errno != EINPROGRESS)) |
631 | { | 631 | { |
632 | /* maybe refused / unsupported address, try next */ | 632 | /* maybe refused / unsupported address, try next */ |
633 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); | 633 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); |
634 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); | 634 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
635 | return NULL; | 635 | return NULL; |
636 | } | 636 | } |
637 | ret = GNUNET_CONNECTION_create_from_existing (sched, s, maxbuf); | 637 | ret = GNUNET_CONNECTION_create_from_existing (sched, s, maxbuf); |
@@ -706,7 +706,7 @@ destroy_continuation (void *cls, | |||
706 | } | 706 | } |
707 | } | 707 | } |
708 | if (sock->sock != NULL) | 708 | if (sock->sock != NULL) |
709 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock->sock)); | 709 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); |
710 | GNUNET_free_non_null (sock->addr); | 710 | GNUNET_free_non_null (sock->addr); |
711 | if (sock->ai != NULL) | 711 | if (sock->ai != NULL) |
712 | freeaddrinfo (sock->ai); | 712 | freeaddrinfo (sock->ai); |
@@ -1075,7 +1075,7 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1075 | if (NULL != sock->sock) | 1075 | if (NULL != sock->sock) |
1076 | { | 1076 | { |
1077 | GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); | 1077 | GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); |
1078 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock->sock)); | 1078 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); |
1079 | sock->sock = NULL; | 1079 | sock->sock = NULL; |
1080 | } | 1080 | } |
1081 | transmit_error (sock); | 1081 | transmit_error (sock); |
@@ -1115,7 +1115,7 @@ RETRY: | |||
1115 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send"); | 1115 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send"); |
1116 | #endif | 1116 | #endif |
1117 | GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); | 1117 | GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); |
1118 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock->sock)); | 1118 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); |
1119 | sock->sock = NULL; | 1119 | sock->sock = NULL; |
1120 | transmit_error (sock); | 1120 | transmit_error (sock); |
1121 | return; | 1121 | return; |
diff --git a/src/util/network.c b/src/util/network.c index ebf329102..ce3f7b40b 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -51,6 +51,14 @@ struct GNUNET_NETWORK_FDSet | |||
51 | #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) | 51 | #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | /** | ||
55 | * accept a new connection on a socket | ||
56 | * | ||
57 | * @param desc bound socket | ||
58 | * @param address address of the connecting peer, may be NULL | ||
59 | * @param address_len length of address | ||
60 | * @return client socket | ||
61 | */ | ||
54 | struct GNUNET_NETWORK_Handle * | 62 | struct GNUNET_NETWORK_Handle * |
55 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | 63 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, |
56 | struct sockaddr *address, | 64 | struct sockaddr *address, |
@@ -67,6 +75,13 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
67 | return ret; | 75 | return ret; |
68 | } | 76 | } |
69 | 77 | ||
78 | /** | ||
79 | * Bind to a connected socket | ||
80 | * @param desc socket | ||
81 | * @param address address to be bound | ||
82 | * @param address_len length of address | ||
83 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
84 | */ | ||
70 | int | 85 | int |
71 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | 86 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, |
72 | const struct sockaddr *address, | 87 | const struct sockaddr *address, |
@@ -79,12 +94,13 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
79 | if (SOCKET_ERROR == ret) | 94 | if (SOCKET_ERROR == ret) |
80 | SetErrnoFromWinsockError (WSAGetLastError ()); | 95 | SetErrnoFromWinsockError (WSAGetLastError ()); |
81 | #endif | 96 | #endif |
82 | return ret; | 97 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; |
83 | } | 98 | } |
84 | 99 | ||
85 | /** | 100 | /** |
86 | * Set if a socket should use blocking or non-blocking IO. | 101 | * Set if a socket should use blocking or non-blocking IO. |
87 | * | 102 | * @param fd socket |
103 | * @param doBlock blocking mode | ||
88 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 104 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
89 | */ | 105 | */ |
90 | int | 106 | int |
@@ -123,6 +139,11 @@ GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, | |||
123 | #endif | 139 | #endif |
124 | } | 140 | } |
125 | 141 | ||
142 | /** | ||
143 | * Close a socket | ||
144 | * @param desc socket | ||
145 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
146 | */ | ||
126 | int | 147 | int |
127 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | 148 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) |
128 | { | 149 | { |
@@ -141,9 +162,16 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | |||
141 | } | 162 | } |
142 | #endif | 163 | #endif |
143 | 164 | ||
144 | return ret; | 165 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; |
145 | } | 166 | } |
146 | 167 | ||
168 | /** | ||
169 | * Connect a socket | ||
170 | * @param desc socket | ||
171 | * @param address peer address | ||
172 | * @param length of address | ||
173 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
174 | */ | ||
147 | int | 175 | int |
148 | GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | 176 | GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, |
149 | const struct sockaddr *address, | 177 | const struct sockaddr *address, |
@@ -156,9 +184,18 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | |||
156 | if (SOCKET_ERROR == ret) | 184 | if (SOCKET_ERROR == ret) |
157 | SetErrnoFromWinsockError (WSAGetLastError ()); | 185 | SetErrnoFromWinsockError (WSAGetLastError ()); |
158 | #endif | 186 | #endif |
159 | return ret; | 187 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; |
160 | } | 188 | } |
161 | 189 | ||
190 | /** | ||
191 | * Get socket options | ||
192 | * @param desc socket | ||
193 | * @param level protocol level of the option | ||
194 | * @param optname identifier of the option | ||
195 | * @param optval options | ||
196 | * @param optlen length of optval | ||
197 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
198 | */ | ||
162 | int | 199 | int |
163 | GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, | 200 | GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, |
164 | int level, int optname, void *optval, | 201 | int level, int optname, void *optval, |
@@ -173,9 +210,15 @@ GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, | |||
173 | else if (SOCKET_ERROR == ret) | 210 | else if (SOCKET_ERROR == ret) |
174 | SetErrnoFromWinsockError (WSAGetLastError ()); | 211 | SetErrnoFromWinsockError (WSAGetLastError ()); |
175 | #endif | 212 | #endif |
176 | return ret; | 213 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; |
177 | } | 214 | } |
178 | 215 | ||
216 | /** | ||
217 | * Listen on a socket | ||
218 | * @param desc socket | ||
219 | * @param backlog length of the listen queue | ||
220 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
221 | */ | ||
179 | int | 222 | int |
180 | GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, | 223 | GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, |
181 | int backlog) | 224 | int backlog) |
@@ -188,9 +231,16 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, | |||
188 | SetErrnoFromWinsockError (WSAGetLastError ()); | 231 | SetErrnoFromWinsockError (WSAGetLastError ()); |
189 | #endif | 232 | #endif |
190 | 233 | ||
191 | return ret; | 234 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; |
192 | } | 235 | } |
193 | 236 | ||
237 | /** | ||
238 | * Read data from a connected socket | ||
239 | * @param desc socket | ||
240 | * @param buffer buffer | ||
241 | * @param length length of buffer | ||
242 | * @param flags type of message reception | ||
243 | */ | ||
194 | ssize_t | 244 | ssize_t |
195 | GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, | 245 | GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, |
196 | void *buffer, size_t length, int flags) | 246 | void *buffer, size_t length, int flags) |
@@ -206,6 +256,14 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, | |||
206 | return ret; | 256 | return ret; |
207 | } | 257 | } |
208 | 258 | ||
259 | /** | ||
260 | * Send data | ||
261 | * @param desc socket | ||
262 | * @param buffer data to send | ||
263 | * @param length size of the buffer | ||
264 | * @param flags type of message transmission | ||
265 | * @return number of bytes sent, GNUNET_SYSERR on error | ||
266 | */ | ||
209 | ssize_t | 267 | ssize_t |
210 | GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, | 268 | GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, |
211 | const void *buffer, size_t length, int flags) | 269 | const void *buffer, size_t length, int flags) |
@@ -221,6 +279,16 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, | |||
221 | return ret; | 279 | return ret; |
222 | } | 280 | } |
223 | 281 | ||
282 | /** | ||
283 | * Send data | ||
284 | * @param desc socket | ||
285 | * @param message data to send | ||
286 | * @param length size of the data | ||
287 | * @param flags type of message transmission | ||
288 | * @param dest_addr destination address | ||
289 | * @param dest_len length of address | ||
290 | * @return number of bytes sent, GNUNET_SYSERR on error | ||
291 | */ | ||
224 | ssize_t | 292 | ssize_t |
225 | GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, | 293 | GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, |
226 | const void *message, size_t length, int flags, | 294 | const void *message, size_t length, int flags, |
@@ -238,6 +306,15 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, | |||
238 | return ret; | 306 | return ret; |
239 | } | 307 | } |
240 | 308 | ||
309 | /** | ||
310 | * Set socket option | ||
311 | * @param fd socket | ||
312 | * @param level protocol level of the option | ||
313 | * @param option_name option identifier | ||
314 | * @param option_value value to set | ||
315 | * @param option_len size of option_value | ||
316 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
317 | */ | ||
241 | int | 318 | int |
242 | GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, | 319 | GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, |
243 | int level, int option_name, | 320 | int level, int option_name, |
@@ -252,9 +329,16 @@ GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, | |||
252 | SetErrnoFromWinsockError (WSAGetLastError ()); | 329 | SetErrnoFromWinsockError (WSAGetLastError ()); |
253 | #endif | 330 | #endif |
254 | 331 | ||
255 | return ret; | 332 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; |
256 | } | 333 | } |
257 | 334 | ||
335 | /** | ||
336 | * Create a new socket | ||
337 | * @param domain domain of the socket | ||
338 | * @param type socket type | ||
339 | * @param protocol network protocol | ||
340 | * @return new socket, NULL on error | ||
341 | */ | ||
258 | struct GNUNET_NETWORK_Handle * | 342 | struct GNUNET_NETWORK_Handle * |
259 | GNUNET_NETWORK_socket_socket (int domain, int type, int protocol) | 343 | GNUNET_NETWORK_socket_socket (int domain, int type, int protocol) |
260 | { | 344 | { |
@@ -276,6 +360,12 @@ GNUNET_NETWORK_socket_socket (int domain, int type, int protocol) | |||
276 | return ret; | 360 | return ret; |
277 | } | 361 | } |
278 | 362 | ||
363 | /** | ||
364 | * Shut down socket operations | ||
365 | * @param desc socket | ||
366 | * @param how type of shutdown | ||
367 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
368 | */ | ||
279 | int | 369 | int |
280 | GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, | 370 | GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, |
281 | int how) | 371 | int how) |
@@ -288,9 +378,15 @@ GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, | |||
288 | SetErrnoFromWinsockError (WSAGetLastError ()); | 378 | SetErrnoFromWinsockError (WSAGetLastError ()); |
289 | #endif | 379 | #endif |
290 | 380 | ||
291 | return ret; | 381 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; |
292 | } | 382 | } |
293 | 383 | ||
384 | /** | ||
385 | * Make a non-inheritable to child processes | ||
386 | * @param socket | ||
387 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | ||
388 | * @warning Not implemented on Windows | ||
389 | */ | ||
294 | int | 390 | int |
295 | GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle | 391 | GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle |
296 | *desc) | 392 | *desc) |
@@ -306,6 +402,10 @@ GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle | |||
306 | #endif | 402 | #endif |
307 | } | 403 | } |
308 | 404 | ||
405 | /** | ||
406 | * Reset FD set | ||
407 | * @param fds fd set | ||
408 | */ | ||
309 | void | 409 | void |
310 | GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds) | 410 | GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds) |
311 | { | 411 | { |
@@ -318,6 +418,11 @@ GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds) | |||
318 | #endif | 418 | #endif |
319 | } | 419 | } |
320 | 420 | ||
421 | /** | ||
422 | * Add a socket to the FD set | ||
423 | * @param fds fd set | ||
424 | * @param desc socket to add | ||
425 | */ | ||
321 | void | 426 | void |
322 | GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, | 427 | GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, |
323 | const struct GNUNET_NETWORK_Handle *desc) | 428 | const struct GNUNET_NETWORK_Handle *desc) |
@@ -328,6 +433,11 @@ GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, | |||
328 | fds->nsds = desc->fd + 1; | 433 | fds->nsds = desc->fd + 1; |
329 | } | 434 | } |
330 | 435 | ||
436 | /** | ||
437 | * Check whether a socket is part of the fd set | ||
438 | * @param fds fd set | ||
439 | * @param desc socket | ||
440 | */ | ||
331 | int | 441 | int |
332 | GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, | 442 | GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, |
333 | const struct GNUNET_NETWORK_Handle *desc) | 443 | const struct GNUNET_NETWORK_Handle *desc) |
@@ -335,6 +445,11 @@ GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, | |||
335 | return FD_ISSET (desc->fd, &fds->sds); | 445 | return FD_ISSET (desc->fd, &fds->sds); |
336 | } | 446 | } |
337 | 447 | ||
448 | /** | ||
449 | * Add one fd set to another | ||
450 | * @param dst the fd set to add to | ||
451 | * @param src the fd set to add from | ||
452 | */ | ||
338 | void | 453 | void |
339 | GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, | 454 | GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, |
340 | const struct GNUNET_NETWORK_FDSet *src) | 455 | const struct GNUNET_NETWORK_FDSet *src) |
@@ -350,6 +465,11 @@ GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, | |||
350 | } | 465 | } |
351 | } | 466 | } |
352 | 467 | ||
468 | /** | ||
469 | * Copy one fd set to another | ||
470 | * @param to destination | ||
471 | * @param from source | ||
472 | */ | ||
353 | void | 473 | void |
354 | GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, | 474 | GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, |
355 | const struct GNUNET_NETWORK_FDSet *from) | 475 | const struct GNUNET_NETWORK_FDSet *from) |
@@ -370,6 +490,12 @@ GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, | |||
370 | #endif | 490 | #endif |
371 | } | 491 | } |
372 | 492 | ||
493 | /** | ||
494 | * Copy a native fd set | ||
495 | * @param to destination | ||
496 | * @param from native source set | ||
497 | * @param the biggest socket number in from + 1 | ||
498 | */ | ||
373 | void | 499 | void |
374 | GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, | 500 | GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, |
375 | const fd_set * from, int nfds) | 501 | const fd_set * from, int nfds) |
@@ -378,6 +504,11 @@ GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, | |||
378 | to->nsds = nfds; | 504 | to->nsds = nfds; |
379 | } | 505 | } |
380 | 506 | ||
507 | /** | ||
508 | * Add a file handle to the fd set | ||
509 | * @param fds fd set | ||
510 | * @param h the file handle to add | ||
511 | */ | ||
381 | void | 512 | void |
382 | GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, | 513 | GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, |
383 | const struct GNUNET_DISK_FileHandle *h) | 514 | const struct GNUNET_DISK_FileHandle *h) |
@@ -397,6 +528,12 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, | |||
397 | #endif | 528 | #endif |
398 | } | 529 | } |
399 | 530 | ||
531 | /** | ||
532 | * Check if a file handle is part of an fd set | ||
533 | * @param fds fd set | ||
534 | * @param h file handle | ||
535 | * @return GNUNET_YES if the file handle is part of the set | ||
536 | */ | ||
400 | int | 537 | int |
401 | GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, | 538 | GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, |
402 | const struct GNUNET_DISK_FileHandle *h) | 539 | const struct GNUNET_DISK_FileHandle *h) |
@@ -409,6 +546,12 @@ GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, | |||
409 | #endif | 546 | #endif |
410 | } | 547 | } |
411 | 548 | ||
549 | /** | ||
550 | * Checks if two fd sets overlap | ||
551 | * @param fds1 first fd set | ||
552 | * @param fds2 second fd set | ||
553 | * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise | ||
554 | */ | ||
412 | int | 555 | int |
413 | GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, | 556 | GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, |
414 | const struct GNUNET_NETWORK_FDSet *fds2) | 557 | const struct GNUNET_NETWORK_FDSet *fds2) |
@@ -426,6 +569,10 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, | |||
426 | return GNUNET_NO; | 569 | return GNUNET_NO; |
427 | } | 570 | } |
428 | 571 | ||
572 | /** | ||
573 | * Creates an fd set | ||
574 | * @return a new fd set | ||
575 | */ | ||
429 | struct GNUNET_NETWORK_FDSet * | 576 | struct GNUNET_NETWORK_FDSet * |
430 | GNUNET_NETWORK_fdset_create () | 577 | GNUNET_NETWORK_fdset_create () |
431 | { | 578 | { |
@@ -440,6 +587,10 @@ GNUNET_NETWORK_fdset_create () | |||
440 | return fds; | 587 | return fds; |
441 | } | 588 | } |
442 | 589 | ||
590 | /** | ||
591 | * Releases the associated memory of an fd set | ||
592 | * @param fds fd set | ||
593 | */ | ||
443 | void | 594 | void |
444 | GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) | 595 | GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) |
445 | { | 596 | { |
@@ -449,6 +600,14 @@ GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) | |||
449 | GNUNET_free (fds); | 600 | GNUNET_free (fds); |
450 | } | 601 | } |
451 | 602 | ||
603 | /** | ||
604 | * Check if sockets meet certain conditions | ||
605 | * @param rfds set of sockets to be checked for readability | ||
606 | * @param wfds set of sockets to be checked for writability | ||
607 | * @param efds set of sockets to be checked for exceptions | ||
608 | * @param timeout relative value when to return | ||
609 | * @return number of selected sockets, GNUNET_SYSERR on error | ||
610 | */ | ||
452 | int | 611 | int |
453 | GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | 612 | GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, |
454 | struct GNUNET_NETWORK_FDSet *wfds, | 613 | struct GNUNET_NETWORK_FDSet *wfds, |
@@ -516,23 +675,6 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
516 | else | 675 | else |
517 | FD_ZERO(&sock_except); | 676 | FD_ZERO(&sock_except); |
518 | 677 | ||
519 | /* | ||
520 | if (rfds) | ||
521 | FD_COPY (&rfds->sds, &sock_read); | ||
522 | else | ||
523 | FD_ZERO(&sock_read); | ||
524 | |||
525 | if (wfds) | ||
526 | FD_COPY (&wfds->sds, &sock_write); | ||
527 | else | ||
528 | FD_ZERO(&sock_write); | ||
529 | |||
530 | if (efds) | ||
531 | FD_COPY (&efds->sds, &sock_except); | ||
532 | else | ||
533 | FD_ZERO(&sock_except); | ||
534 | */ | ||
535 | |||
536 | /* multiplex between winsock select() and waiting on the handles */ | 678 | /* multiplex between winsock select() and waiting on the handles */ |
537 | 679 | ||
538 | FD_ZERO (&aread); | 680 | FD_ZERO (&aread); |
diff --git a/src/util/server.c b/src/util/server.c index ca084e622..b43735132 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -324,7 +324,7 @@ process_listen_socket (void *cls, | |||
324 | { | 324 | { |
325 | /* shutdown was initiated */ | 325 | /* shutdown was initiated */ |
326 | GNUNET_assert (server->listen_socket != NULL); | 326 | GNUNET_assert (server->listen_socket != NULL); |
327 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (server->listen_socket)); | 327 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (server->listen_socket)); |
328 | server->listen_socket = NULL; | 328 | server->listen_socket = NULL; |
329 | if (server->do_shutdown) | 329 | if (server->do_shutdown) |
330 | destroy_server (server); | 330 | destroy_server (server); |
@@ -402,20 +402,20 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) | |||
402 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 402 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
403 | "setsockopt"); | 403 | "setsockopt"); |
404 | /* bind the socket */ | 404 | /* bind the socket */ |
405 | if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) < 0) | 405 | if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK) |
406 | { | 406 | { |
407 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 407 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); |
408 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 408 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
409 | _ | 409 | _ |
410 | ("`%s' failed for port %d. Is the service already running?\n"), | 410 | ("`%s' failed for port %d. Is the service already running?\n"), |
411 | "bind", port); | 411 | "bind", port); |
412 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock)); | 412 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
413 | return NULL; | 413 | return NULL; |
414 | } | 414 | } |
415 | if (0 != GNUNET_NETWORK_socket_listen (sock, 5)) | 415 | if (0 != GNUNET_NETWORK_socket_listen (sock, 5)) |
416 | { | 416 | { |
417 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); | 417 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); |
418 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock)); | 418 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
419 | return NULL; | 419 | return NULL; |
420 | } | 420 | } |
421 | #if DEBUG_SERVER | 421 | #if DEBUG_SERVER |
@@ -468,7 +468,7 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, | |||
468 | ret->shutpipe = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileDescriptor *[2])); | 468 | ret->shutpipe = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileDescriptor *[2])); |
469 | if (NULL == (ret->shutpipe = GNUNET_DISK_pipe (GNUNET_NO))) | 469 | if (NULL == (ret->shutpipe = GNUNET_DISK_pipe (GNUNET_NO))) |
470 | { | 470 | { |
471 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (lsock)); | 471 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsock)); |
472 | GNUNET_free (ret->shutpipe); | 472 | GNUNET_free (ret->shutpipe); |
473 | GNUNET_free (ret); | 473 | GNUNET_free (ret); |
474 | return NULL; | 474 | return NULL; |
diff --git a/src/util/service.c b/src/util/service.c index 1f363788e..efcfa50c9 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -836,7 +836,7 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) | |||
836 | } | 836 | } |
837 | } | 837 | } |
838 | if (NULL != desc) | 838 | if (NULL != desc) |
839 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (desc)); | 839 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); |
840 | } | 840 | } |
841 | 841 | ||
842 | 842 | ||
diff --git a/src/util/test_connection.c b/src/util/test_connection.c index dfa6d70b4..2f82072f9 100644 --- a/src/util/test_connection.c +++ b/src/util/test_connection.c | |||
@@ -66,7 +66,7 @@ open_listen_socket () | |||
66 | "setsockopt"); | 66 | "setsockopt"); |
67 | GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, | 67 | GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, |
68 | (const struct sockaddr*) &sa, | 68 | (const struct sockaddr*) &sa, |
69 | sizeof (sa)) >= 0); | 69 | sizeof (sa)) == GNUNET_OK); |
70 | GNUNET_NETWORK_socket_listen (desc, 5); | 70 | GNUNET_NETWORK_socket_listen (desc, 5); |
71 | return desc; | 71 | return desc; |
72 | } | 72 | } |
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c index 17ef4d11a..b1decebc3 100644 --- a/src/util/test_connection_addressing.c +++ b/src/util/test_connection_addressing.c | |||
@@ -65,7 +65,7 @@ open_listen_socket () | |||
65 | "setsockopt"); | 65 | "setsockopt"); |
66 | GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, | 66 | GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, |
67 | (const struct sockaddr*) &sa, | 67 | (const struct sockaddr*) &sa, |
68 | sizeof (sa)) >= 0); | 68 | sizeof (sa)) == GNUNET_OK); |
69 | GNUNET_NETWORK_socket_listen (desc, 5); | 69 | GNUNET_NETWORK_socket_listen (desc, 5); |
70 | return desc; | 70 | return desc; |
71 | } | 71 | } |
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c index aa1340e02..003138530 100644 --- a/src/util/test_connection_receive_cancel.c +++ b/src/util/test_connection_receive_cancel.c | |||
@@ -66,7 +66,7 @@ open_listen_socket () | |||
66 | "setsockopt"); | 66 | "setsockopt"); |
67 | GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, | 67 | GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, |
68 | (const struct sockaddr*) &sa, | 68 | (const struct sockaddr*) &sa, |
69 | sizeof (sa)) >= 0); | 69 | sizeof (sa)) == GNUNET_OK); |
70 | GNUNET_NETWORK_socket_listen (desc, 5); | 70 | GNUNET_NETWORK_socket_listen (desc, 5); |
71 | return desc; | 71 | return desc; |
72 | } | 72 | } |
diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c index 2580ae30a..3a4b69d67 100644 --- a/src/util/test_connection_timeout.c +++ b/src/util/test_connection_timeout.c | |||
@@ -59,7 +59,7 @@ open_listen_socket () | |||
59 | "setsockopt"); | 59 | "setsockopt"); |
60 | GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, | 60 | GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, |
61 | (const struct sockaddr*) &sa, | 61 | (const struct sockaddr*) &sa, |
62 | sizeof (sa)) >= 0); | 62 | sizeof (sa)) == GNUNET_OK); |
63 | GNUNET_NETWORK_socket_listen (desc, 5); | 63 | GNUNET_NETWORK_socket_listen (desc, 5); |
64 | return desc; | 64 | return desc; |
65 | } | 65 | } |
diff --git a/src/util/test_service.c b/src/util/test_service.c index e0cfe28ac..e9070a912 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -326,7 +326,7 @@ main (int argc, char *argv[]) | |||
326 | } | 326 | } |
327 | else | 327 | else |
328 | { | 328 | { |
329 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); | 329 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
330 | ret += check6 (); | 330 | ret += check6 (); |
331 | ret += check6d (); /* with daemonization */ | 331 | ret += check6d (); /* with daemonization */ |
332 | } | 332 | } |