diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2021-11-13 22:37:15 +0100 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2021-11-13 22:37:37 +0100 |
commit | d06c9fa38337c454e0144fccd892f7353c533eef (patch) | |
tree | 430e6ea391b60a79893e8d7be7703b6d3760afab | |
parent | 3af9a8c295a1a17adddb2127aa151723cd7c396c (diff) | |
download | gnunet-d06c9fa38337c454e0144fccd892f7353c533eef.tar.gz gnunet-d06c9fa38337c454e0144fccd892f7353c533eef.zip |
-minor code cleanup
-rw-r--r-- | src/include/gnunet_network_lib.h | 16 | ||||
-rw-r--r-- | src/util/network.c | 61 |
2 files changed, 12 insertions, 65 deletions
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index 97ab64add..ff1e853f5 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h | |||
@@ -78,7 +78,7 @@ struct GNUNET_NETWORK_FDSet | |||
78 | * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX) | 78 | * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX) |
79 | * @return #GNUNET_OK if the PF is supported | 79 | * @return #GNUNET_OK if the PF is supported |
80 | */ | 80 | */ |
81 | int | 81 | enum GNUNET_GenericReturnValue |
82 | GNUNET_NETWORK_test_pf (int pf); | 82 | GNUNET_NETWORK_test_pf (int pf); |
83 | 83 | ||
84 | 84 | ||
@@ -154,7 +154,7 @@ GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, | |||
154 | * @param address_len length of @a address | 154 | * @param address_len length of @a address |
155 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 155 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
156 | */ | 156 | */ |
157 | int | 157 | enum GNUNET_GenericReturnValue |
158 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | 158 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, |
159 | const struct sockaddr *address, | 159 | const struct sockaddr *address, |
160 | socklen_t address_len); | 160 | socklen_t address_len); |
@@ -165,7 +165,7 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
165 | * @param desc socket to close | 165 | * @param desc socket to close |
166 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 166 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
167 | */ | 167 | */ |
168 | int | 168 | enum GNUNET_GenericReturnValue |
169 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc); | 169 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc); |
170 | 170 | ||
171 | 171 | ||
@@ -186,7 +186,7 @@ GNUNET_NETWORK_socket_free_memory_only_ (struct GNUNET_NETWORK_Handle *desc); | |||
186 | * @param address_len of @a address | 186 | * @param address_len of @a address |
187 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 187 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
188 | */ | 188 | */ |
189 | int | 189 | enum GNUNET_GenericReturnValue |
190 | GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | 190 | GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, |
191 | const struct sockaddr *address, | 191 | const struct sockaddr *address, |
192 | socklen_t address_len); | 192 | socklen_t address_len); |
@@ -202,7 +202,7 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | |||
202 | * @param optlen length of optval | 202 | * @param optlen length of optval |
203 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 203 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
204 | */ | 204 | */ |
205 | int | 205 | enum GNUNET_GenericReturnValue |
206 | GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, | 206 | GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, |
207 | int level, | 207 | int level, |
208 | int optname, | 208 | int optname, |
@@ -217,7 +217,7 @@ GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, | |||
217 | * @param backlog length of the listen queue | 217 | * @param backlog length of the listen queue |
218 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 218 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
219 | */ | 219 | */ |
220 | int | 220 | enum GNUNET_GenericReturnValue |
221 | GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, | 221 | GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, |
222 | int backlog); | 222 | int backlog); |
223 | 223 | ||
@@ -339,7 +339,7 @@ GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, | |||
339 | * @param how type of shutdown | 339 | * @param how type of shutdown |
340 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 340 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
341 | */ | 341 | */ |
342 | int | 342 | enum GNUNET_GenericReturnValue |
343 | GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, | 343 | GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, |
344 | int how); | 344 | int how); |
345 | 345 | ||
@@ -353,7 +353,7 @@ GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, | |||
353 | * @param desc socket | 353 | * @param desc socket |
354 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 354 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
355 | */ | 355 | */ |
356 | int | 356 | enum GNUNET_GenericReturnValue |
357 | GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc); | 357 | GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc); |
358 | 358 | ||
359 | 359 | ||
diff --git a/src/util/network.c b/src/util/network.c index 014701e02..688c37665 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -75,13 +75,7 @@ struct GNUNET_NETWORK_Handle | |||
75 | }; | 75 | }; |
76 | 76 | ||
77 | 77 | ||
78 | /** | 78 | enum GNUNET_GenericReturnValue |
79 | * Test if the given protocol family is supported by this system. | ||
80 | * | ||
81 | * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX) | ||
82 | * @return #GNUNET_OK if the PF is supported | ||
83 | */ | ||
84 | int | ||
85 | GNUNET_NETWORK_test_pf (int pf) | 79 | GNUNET_NETWORK_test_pf (int pf) |
86 | { | 80 | { |
87 | static int cache_v4 = -1; | 81 | static int cache_v4 = -1; |
@@ -145,15 +139,6 @@ GNUNET_NETWORK_test_pf (int pf) | |||
145 | } | 139 | } |
146 | 140 | ||
147 | 141 | ||
148 | /** | ||
149 | * Given a unixpath that is too long (larger than UNIX_PATH_MAX), | ||
150 | * shorten it to an acceptable length while keeping it unique | ||
151 | * and making sure it remains a valid filename (if possible). | ||
152 | * | ||
153 | * @param unixpath long path, will be freed (or same pointer returned | ||
154 | * with moved 0-termination). | ||
155 | * @return shortened unixpath, NULL on error | ||
156 | */ | ||
157 | char * | 142 | char * |
158 | GNUNET_NETWORK_shorten_unixpath (char *unixpath) | 143 | GNUNET_NETWORK_shorten_unixpath (char *unixpath) |
159 | { | 144 | { |
@@ -189,15 +174,6 @@ GNUNET_NETWORK_shorten_unixpath (char *unixpath) | |||
189 | } | 174 | } |
190 | 175 | ||
191 | 176 | ||
192 | /** | ||
193 | * If services crash, they can leave a unix domain socket file on the | ||
194 | * disk. This needs to be manually removed, because otherwise both | ||
195 | * bind() and connect() for the respective address will fail. In this | ||
196 | * function, we test if such a left-over file exists, and if so, | ||
197 | * remove it (unless there is a listening service at the address). | ||
198 | * | ||
199 | * @param un unix domain socket address to check | ||
200 | */ | ||
201 | void | 177 | void |
202 | GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un) | 178 | GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un) |
203 | { | 179 | { |
@@ -244,14 +220,7 @@ GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un) | |||
244 | #endif | 220 | #endif |
245 | 221 | ||
246 | 222 | ||
247 | /** | 223 | enum GNUNET_GenericReturnValue |
248 | * Set if a socket should use blocking or non-blocking IO. | ||
249 | * | ||
250 | * @param fd socket | ||
251 | * @param doBlock blocking mode | ||
252 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
253 | */ | ||
254 | int | ||
255 | GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, | 224 | GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, |
256 | int doBlock) | 225 | int doBlock) |
257 | { | 226 | { |
@@ -418,14 +387,6 @@ initialize_network_handle (struct GNUNET_NETWORK_Handle *h, | |||
418 | } | 387 | } |
419 | 388 | ||
420 | 389 | ||
421 | /** | ||
422 | * accept a new connection on a socket | ||
423 | * | ||
424 | * @param desc bound socket | ||
425 | * @param address address of the connecting peer, may be NULL | ||
426 | * @param address_len length of @a address | ||
427 | * @return client socket | ||
428 | */ | ||
429 | struct GNUNET_NETWORK_Handle * | 390 | struct GNUNET_NETWORK_Handle * |
430 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | 391 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, |
431 | struct sockaddr *address, | 392 | struct sockaddr *address, |
@@ -473,15 +434,7 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
473 | } | 434 | } |
474 | 435 | ||
475 | 436 | ||
476 | /** | 437 | enum GNUNET_GenericReturnValue |
477 | * Bind a socket to a particular address. | ||
478 | * | ||
479 | * @param desc socket to bind | ||
480 | * @param address address to be bound | ||
481 | * @param address_len length of @a address | ||
482 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
483 | */ | ||
484 | int | ||
485 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | 438 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, |
486 | const struct sockaddr *address, | 439 | const struct sockaddr *address, |
487 | socklen_t address_len) | 440 | socklen_t address_len) |
@@ -550,13 +503,7 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
550 | } | 503 | } |
551 | 504 | ||
552 | 505 | ||
553 | /** | 506 | enum GNUNET_GenericReturnValue |
554 | * Close a socket | ||
555 | * | ||
556 | * @param desc socket | ||
557 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
558 | */ | ||
559 | int | ||
560 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | 507 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) |
561 | { | 508 | { |
562 | int ret; | 509 | int ret; |