From: Urban Wallasch Date: Wed, 23 Oct 2019 20:50:40 +0000 (+0200) Subject: * net: changed order of function definitions; comment reformatting X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=e18c72dec261fa3187e4cccdf2d8cdf6dfb658b5;p=oddbits.git * net: changed order of function definitions; comment reformatting --- diff --git a/net/net.c b/net/net.c index 6de3cf0..af9b43c 100644 --- a/net/net.c +++ b/net/net.c @@ -108,6 +108,17 @@ static int net_bind_local(int sock, const char *addr, int st, int af ) { return err < 0 ? EAI_SYSTEM : 0; } +/* Copy textual description of last error to user supplied buffer: */ +char *net_strerror(int errnum, char *buf, size_t len) { + if (errnum >= 0) + snprintf(buf, len, "Success"); + else if (errnum == EAI_SYSTEM) + strerror_r(errno, buf, len); + else + snprintf(buf, len, gai_strerror(errnum)); + return buf; +} + /* Create and bind a new listener socket: */ int net_open_server(const char *addr, const char *svc, int st, int af) { int err, sock = -1; @@ -224,7 +235,7 @@ int net_close(int sock) { int err; err = shutdown(sock, SHUT_RDWR); if (err < 0) { - /* This "error" is never reported back to caller! */ + /* This error is not forwarded to caller! */ NETLOG_DBG("shutdown(%d): %s", sock, strerror(errno)); } err = close(sock); @@ -279,17 +290,6 @@ int tcp_accept(int sock, int timeout) { return r; } -/* Copy textual description of last error to user supplied buffer: */ -char *net_strerror(int errnum, char *buf, size_t len) { - if (errnum >= 0) - snprintf(buf, len, "Success"); - else if (errnum == EAI_SYSTEM) - strerror_r(errno, buf, len); - else - snprintf(buf, len, gai_strerror(errnum)); - return buf; -} - /* Read from socket or file descriptor: */ ssize_t recvfrom_tm(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen, int timeout) { diff --git a/net/net.h b/net/net.h index f209dec..6fe5704 100644 --- a/net/net.h +++ b/net/net.h @@ -17,11 +17,13 @@ * * net_strerror - get textual error message * - * recvfrom_tm, recv_tm, read_tm - * - functions and macros to read with timeout + * recvfrom_tm + * recv_tm + * read_tm - functions and macros to read with timeout * - * sendto_tm, send_tm, write_tm - * - functions and macros to write with timeout + * sendto_tm + * send_tm + * write_tm - functions and macros to write with timeout * */ @@ -34,6 +36,21 @@ extern "C" { #include +/* + * Copy textual description of last error to user supplied buffer. + * + * Returns a pointer to the buffer. + * + * errnum - error code returned by any of the above functions + * buf - user supplied buffer to store the error message + * len - maximum number of characters buf can hold + * + * Note: Depending on the actual value of errnum this function will + * return a message based on either strerror_r() or gai_strerror(). + */ +extern char *net_strerror(int errnum, char *buf, size_t len); + + /* * Create a new socket with the specified characteristics, bind it to * the local node address and, in case of SOCK_STREAM, start listening @@ -95,6 +112,9 @@ extern int net_open_client(const char *host, const char *svc, const char *addr, * * Returns 0 on success, or a negative value on error. * + * Note: Errors returned by shutdown() are silently ignored and not + * forwarded. + * * sock - socket to close */ extern int net_close(int sock); @@ -118,21 +138,6 @@ extern int net_close(int sock); extern int tcp_accept(int sock, int timeout); -/* - * Copy textual description of last error to user supplied buffer. - * - * Returns a pointer to the buffer. - * - * errnum - error code returned by any of the above functions - * buf - user supplied buffer to store the error message - * len - maximum number of characters buf can hold - * - * Note: Depending on the actual value of errnum this function will - * return a message based on either strerror_r() or gai_strerror(). - */ -extern char *net_strerror(int errnum, char *buf, size_t len); - - /* * Read from file or socket descriptor with timeout. *