From a095a849fcd95efeb57db80b4346e4f2eedf9899 Mon Sep 17 00:00:00 2001 From: Nils Durner Date: Sun, 30 Aug 2009 21:06:23 +0000 Subject: [PATCH] docs & GNUnet-style return codes --- src/include/gnunet_network_lib.h | 170 +++++++++++++++++-- src/util/connection.c | 24 +-- src/util/network.c | 192 +++++++++++++++++++--- src/util/server.c | 10 +- src/util/service.c | 2 +- src/util/test_connection.c | 2 +- src/util/test_connection_addressing.c | 2 +- src/util/test_connection_receive_cancel.c | 2 +- src/util/test_connection_timeout.c | 2 +- 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; #include "gnunet_disk_lib.h" #include "gnunet_time_lib.h" - +/** + * accept a new connection on a socket + * + * @param desc bound socket + * @param address address of the connecting peer, may be NULL + * @param address_len length of address + * @return client socket + */ struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len); +/** + * Make a non-inheritable to child processes + * @param socket + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + * @warning Not implemented on Windows + */ int GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle *desc); - +/** + * Bind to a connected socket + * @param desc socket + * @param address address to be bound + * @param address_len length of address + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len); +/** + * Close a socket + * @param desc socket + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc); +/** + * Connect a socket + * @param desc socket + * @param address peer address + * @param length of address + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len); +/** + * Get socket options + * @param desc socket + * @param level protocol level of the option + * @param optname identifier of the option + * @param optval options + * @param optlen length of optval + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname, void *optval, socklen_t *optlen); +/** + * Listen on a socket + * @param desc socket + * @param backlog length of the listen queue + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog); -ssize_t GNUNET_NETWORK_socket_read (const struct GNUNET_NETWORK_Handle *desc, void *buf, - size_t nbyte); - +/** + * Read data from a connected socket + * @param desc socket + * @param buffer buffer + * @param length length of buffer + * @param flags type of message reception + */ ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, int flags); +/** + * Check if sockets meet certain conditions + * @param rfds set of sockets to be checked for readability + * @param wfds set of sockets to be checked for writability + * @param efds set of sockets to be checked for exceptions + * @param timeout relative value when to return + * @return number of selected sockets, GNUNET_SYSERR on error + */ int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds, struct GNUNET_TIME_Relative timeout); /** * Set if a socket should use blocking or non-blocking IO. - * + * @param fd socket + * @param doBlock blocking mode * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock); +/** + * Send data + * @param desc socket + * @param buffer data to send + * @param length size of the buffer + * @param flags type of message transmission + * @return number of bytes sent, GNUNET_SYSERR on error + */ ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length, int flags); +/** + * Send data + * @param desc socket + * @param message data to send + * @param length size of the data + * @param flags type of message transmission + * @param dest_addr destination address + * @param dest_len length of address + * @return number of bytes sent, GNUNET_SYSERR on error + */ ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len); +/** + * Set socket option + * @param fd socket + * @param level protocol level of the option + * @param option_name option identifier + * @param option_value value to set + * @param option_len size of option_value + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len); +/** + * Shut down socket operations + * @param desc socket + * @param how type of shutdown + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how); +/** + * Create a new socket + * @param domain domain of the socket + * @param type socket type + * @param protocol network protocol + * @return new socket, NULL on error + */ struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol); -ssize_t GNUNET_NETWORK_socket_write (const struct GNUNET_NETWORK_Handle *desc, - const void *buf, size_t nbyte); - - +/** + * Reset FD set + * @param fds fd set + */ void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds); +/** + * Add a socket to the FD set + * @param fds fd set + * @param desc socket to add + */ void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc); +/** + * Check whether a socket is part of the fd set + * @param fds fd set + * @param desc socket + */ int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc); +/** + * Add one fd set to another + * @param dst the fd set to add to + * @param src the fd set to add from + */ void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, const struct GNUNET_NETWORK_FDSet *src); +/** + * Copy one fd set to another + * @param to destination + * @param from source + */ void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to, const struct GNUNET_NETWORK_FDSet *from); +/** + * Copy a native fd set + * @param to destination + * @param from native source set + * @param the biggest socket number in from + 1 + */ void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds); +/** + * Add a file handle to the fd set + * @param fds fd set + * @param h the file handle to add + */ void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_DISK_FileHandle *h); +/** + * Check if a file handle is part of an fd set + * @param fds fd set + * @param h file handle + * @return GNUNET_YES if the file handle is part of the set + */ int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_DISK_FileHandle *h); +/** + * Checks if two fd sets overlap + * @param fds1 first fd set + * @param fds2 second fd set + * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise + */ int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2); +/** + * Creates an fd set + * @return a new fd set + */ struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create (void); +/** + * Releases the associated memory of an fd set + * @param fds fd set + */ void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds); 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 if (addrlen > sizeof (addr)) { GNUNET_break (0); - GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); return NULL; } @@ -310,7 +310,7 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle _("Access denied to `%s'\n"), GNUNET_a2s(uaddr, addrlen)); GNUNET_break (0 == GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); - GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); GNUNET_free (uaddr); return NULL; } @@ -436,7 +436,7 @@ try_connect (struct GNUNET_CONNECTION_Handle *sock) if (GNUNET_SYSERR == GNUNET_NETWORK_socket_set_blocking (s, GNUNET_NO)) { /* we'll treat this one as fatal */ - GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); return GNUNET_SYSERR; } #if DEBUG_CONNECTION @@ -445,13 +445,13 @@ try_connect (struct GNUNET_CONNECTION_Handle *sock) GNUNET_a2s(sock->ai_pos->ai_addr, sock->ai_pos->ai_addrlen)); #endif - if ((0 != GNUNET_NETWORK_socket_connect (s, + if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, sock->ai_pos->ai_addr, sock->ai_pos->ai_addrlen)) && (errno != EINPROGRESS)) { /* maybe refused / unsupported address, try next */ GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); - GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); sock->ai_pos = sock->ai_pos->ai_next; continue; } @@ -497,7 +497,7 @@ connect_continuation (void *cls, GNUNET_a2s(sock->addr, sock->addrlen)); #endif /* connect failed / timed out */ - GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock->sock)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); sock->sock = NULL; if (GNUNET_SYSERR == try_connect (sock)) { @@ -619,7 +619,7 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle if (GNUNET_SYSERR == GNUNET_NETWORK_socket_set_blocking (s, GNUNET_NO)) { /* we'll treat this one as fatal */ - GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); return NULL; } #if DEBUG_CONNECTION @@ -627,11 +627,11 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle _("Trying to connect to `%s'\n"), GNUNET_a2s(serv_addr, addrlen)); #endif - if ((0 != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && (errno != EINPROGRESS)) + if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && (errno != EINPROGRESS)) { /* maybe refused / unsupported address, try next */ GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); - GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); return NULL; } ret = GNUNET_CONNECTION_create_from_existing (sched, s, maxbuf); @@ -706,7 +706,7 @@ destroy_continuation (void *cls, } } if (sock->sock != NULL) - GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock->sock)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); GNUNET_free_non_null (sock->addr); if (sock->ai != NULL) freeaddrinfo (sock->ai); @@ -1075,7 +1075,7 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (NULL != sock->sock) { GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); - GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock->sock)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); sock->sock = NULL; } transmit_error (sock); @@ -1115,7 +1115,7 @@ RETRY: GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send"); #endif GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); - GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock->sock)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); sock->sock = NULL; transmit_error (sock); 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 #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) #endif +/** + * accept a new connection on a socket + * + * @param desc bound socket + * @param address address of the connecting peer, may be NULL + * @param address_len length of address + * @return client socket + */ struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, @@ -67,6 +75,13 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, return ret; } +/** + * Bind to a connected socket + * @param desc socket + * @param address address to be bound + * @param address_len length of address + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, @@ -79,12 +94,13 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, if (SOCKET_ERROR == ret) SetErrnoFromWinsockError (WSAGetLastError ()); #endif - return ret; + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } /** * Set if a socket should use blocking or non-blocking IO. - * + * @param fd socket + * @param doBlock blocking mode * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int @@ -123,6 +139,11 @@ GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, #endif } +/** + * Close a socket + * @param desc socket + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) { @@ -141,9 +162,16 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) } #endif - return ret; + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } +/** + * Connect a socket + * @param desc socket + * @param address peer address + * @param length of address + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, @@ -156,9 +184,18 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, if (SOCKET_ERROR == ret) SetErrnoFromWinsockError (WSAGetLastError ()); #endif - return ret; + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } +/** + * Get socket options + * @param desc socket + * @param level protocol level of the option + * @param optname identifier of the option + * @param optval options + * @param optlen length of optval + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, int level, int optname, void *optval, @@ -173,9 +210,15 @@ GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, else if (SOCKET_ERROR == ret) SetErrnoFromWinsockError (WSAGetLastError ()); #endif - return ret; + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } +/** + * Listen on a socket + * @param desc socket + * @param backlog length of the listen queue + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, int backlog) @@ -188,9 +231,16 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, SetErrnoFromWinsockError (WSAGetLastError ()); #endif - return ret; + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } +/** + * Read data from a connected socket + * @param desc socket + * @param buffer buffer + * @param length length of buffer + * @param flags type of message reception + */ ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, void *buffer, size_t length, int flags) @@ -206,6 +256,14 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, return ret; } +/** + * Send data + * @param desc socket + * @param buffer data to send + * @param length size of the buffer + * @param flags type of message transmission + * @return number of bytes sent, GNUNET_SYSERR on error + */ ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, const void *buffer, size_t length, int flags) @@ -221,6 +279,16 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, return ret; } +/** + * Send data + * @param desc socket + * @param message data to send + * @param length size of the data + * @param flags type of message transmission + * @param dest_addr destination address + * @param dest_len length of address + * @return number of bytes sent, GNUNET_SYSERR on error + */ ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, const void *message, size_t length, int flags, @@ -238,6 +306,15 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, return ret; } +/** + * Set socket option + * @param fd socket + * @param level protocol level of the option + * @param option_name option identifier + * @param option_value value to set + * @param option_len size of option_value + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level, int option_name, @@ -252,9 +329,16 @@ GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, SetErrnoFromWinsockError (WSAGetLastError ()); #endif - return ret; + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } +/** + * Create a new socket + * @param domain domain of the socket + * @param type socket type + * @param protocol network protocol + * @return new socket, NULL on error + */ struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_socket (int domain, int type, int protocol) { @@ -276,6 +360,12 @@ GNUNET_NETWORK_socket_socket (int domain, int type, int protocol) return ret; } +/** + * Shut down socket operations + * @param desc socket + * @param how type of shutdown + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how) @@ -288,9 +378,15 @@ GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, SetErrnoFromWinsockError (WSAGetLastError ()); #endif - return ret; + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } +/** + * Make a non-inheritable to child processes + * @param socket + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + * @warning Not implemented on Windows + */ int GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle *desc) @@ -306,6 +402,10 @@ GNUNET_NETWORK_socket_set_inheritable (const struct GNUNET_NETWORK_Handle #endif } +/** + * Reset FD set + * @param fds fd set + */ void GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds) { @@ -318,6 +418,11 @@ GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds) #endif } +/** + * Add a socket to the FD set + * @param fds fd set + * @param desc socket to add + */ void GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc) @@ -328,6 +433,11 @@ GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, fds->nsds = desc->fd + 1; } +/** + * Check whether a socket is part of the fd set + * @param fds fd set + * @param desc socket + */ int GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc) @@ -335,6 +445,11 @@ GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, return FD_ISSET (desc->fd, &fds->sds); } +/** + * Add one fd set to another + * @param dst the fd set to add to + * @param src the fd set to add from + */ void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, const struct GNUNET_NETWORK_FDSet *src) @@ -350,6 +465,11 @@ GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, } } +/** + * Copy one fd set to another + * @param to destination + * @param from source + */ void GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, const struct GNUNET_NETWORK_FDSet *from) @@ -370,6 +490,12 @@ GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, #endif } +/** + * Copy a native fd set + * @param to destination + * @param from native source set + * @param the biggest socket number in from + 1 + */ void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set * from, int nfds) @@ -378,6 +504,11 @@ GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, to->nsds = nfds; } +/** + * Add a file handle to the fd set + * @param fds fd set + * @param h the file handle to add + */ void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_DISK_FileHandle *h) @@ -397,6 +528,12 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, #endif } +/** + * Check if a file handle is part of an fd set + * @param fds fd set + * @param h file handle + * @return GNUNET_YES if the file handle is part of the set + */ int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_DISK_FileHandle *h) @@ -409,6 +546,12 @@ GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, #endif } +/** + * Checks if two fd sets overlap + * @param fds1 first fd set + * @param fds2 second fd set + * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise + */ int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2) @@ -426,6 +569,10 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, return GNUNET_NO; } +/** + * Creates an fd set + * @return a new fd set + */ struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create () { @@ -440,6 +587,10 @@ GNUNET_NETWORK_fdset_create () return fds; } +/** + * Releases the associated memory of an fd set + * @param fds fd set + */ void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) { @@ -449,6 +600,14 @@ GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) GNUNET_free (fds); } +/** + * Check if sockets meet certain conditions + * @param rfds set of sockets to be checked for readability + * @param wfds set of sockets to be checked for writability + * @param efds set of sockets to be checked for exceptions + * @param timeout relative value when to return + * @return number of selected sockets, GNUNET_SYSERR on error + */ int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, struct GNUNET_NETWORK_FDSet *wfds, @@ -516,23 +675,6 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, else FD_ZERO(&sock_except); - /* - if (rfds) - FD_COPY (&rfds->sds, &sock_read); - else - FD_ZERO(&sock_read); - - if (wfds) - FD_COPY (&wfds->sds, &sock_write); - else - FD_ZERO(&sock_write); - - if (efds) - FD_COPY (&efds->sds, &sock_except); - else - FD_ZERO(&sock_except); -*/ - /* multiplex between winsock select() and waiting on the handles */ 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, { /* shutdown was initiated */ GNUNET_assert (server->listen_socket != NULL); - GNUNET_break (0 == GNUNET_NETWORK_socket_close (server->listen_socket)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (server->listen_socket)); server->listen_socket = NULL; if (server->do_shutdown) destroy_server (server); @@ -402,20 +402,20 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); /* bind the socket */ - if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) < 0) + if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("`%s' failed for port %d. Is the service already running?\n"), "bind", port); - GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); return NULL; } if (0 != GNUNET_NETWORK_socket_listen (sock, 5)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); - GNUNET_break (0 == GNUNET_NETWORK_socket_close (sock)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); return NULL; } #if DEBUG_SERVER @@ -468,7 +468,7 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, ret->shutpipe = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileDescriptor *[2])); if (NULL == (ret->shutpipe = GNUNET_DISK_pipe (GNUNET_NO))) { - GNUNET_break (0 == GNUNET_NETWORK_socket_close (lsock)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsock)); GNUNET_free (ret->shutpipe); GNUNET_free (ret); 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) } } if (NULL != desc) - GNUNET_break (0 == GNUNET_NETWORK_socket_close (desc)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); } 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 () "setsockopt"); GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr*) &sa, - sizeof (sa)) >= 0); + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } 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 () "setsockopt"); GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr*) &sa, - sizeof (sa)) >= 0); + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } 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 () "setsockopt"); GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr*) &sa, - sizeof (sa)) >= 0); + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } 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 () "setsockopt"); GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr*) &sa, - sizeof (sa)) >= 0); + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } 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[]) } else { - GNUNET_break (0 == GNUNET_NETWORK_socket_close (s)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); ret += check6 (); ret += check6d (); /* with daemonization */ } -- 2.25.1