From 990ca94b15b725b0a54a8603b34a47635c6436f0 Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Tue, 22 Oct 2019 18:45:59 +0200 Subject: [PATCH] * changed prototype of net_strerror() * improved comments --- net/net.c | 2 +- net/net.h | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/net/net.c b/net/net.c index 89e8da0..9991c6b 100644 --- a/net/net.c +++ b/net/net.c @@ -276,7 +276,7 @@ int tcp_accept(int sock, int timeout) { } /* Copy textual description of last error to user supplied buffer: */ -const char *net_strerror(int errnum, char *buf, size_t len) { +char *net_strerror(int errnum, char *buf, size_t len) { if ( errnum == EAI_SYSTEM ) strerror_r(errno, buf, len); else diff --git a/net/net.h b/net/net.h index c430046..33c09e2 100644 --- a/net/net.h +++ b/net/net.h @@ -23,7 +23,8 @@ extern "C" { * Create a new socket with the specified characteristics, bind it to * the local node address and, in case of SOCK_STREAM, start listening * for connection requests which can be accepted using tcp_accept(). - * Returns the listener socket or a negative value on error. + * + * Returns the bound listener socket, or a negative value on error. * * addr - local node address (numerical or name); NULL for any * svc - service (port number or service name) @@ -31,6 +32,9 @@ extern "C" { * af - address family; one of AF_UNSPEC, AF_INET, AF_INET6 * * Note: Address family AF_INET6 will still allow V4MAPPED connections. + * AF_UNSPEC will cause the first suitable bind address to be used, + * the sort order is determined by the host configuration, e.g. in + * /etc/gai.conf for glibc. */ extern int net_open_server(const char *addr, const char *svc, int st, int af); @@ -46,10 +50,11 @@ extern int net_open_server(const char *addr, const char *svc, int st, int af); /* - * Create a new socket, optionally bind it to a local node, associate - * it with a random ephemeral port and connect it to the specified host - * and service. - * Returns the connected socket or a negative value on error. + * Create a new socket, optionally bind it to a local node address, + * associate it with a random ephemeral port and connect it to the + * specified host and service. + * + * Returns the connected socket, or a negative value on error. * * host - remote node address (numerical or host name) * svc - remote service (port number or service name) @@ -72,7 +77,8 @@ extern int net_open_client(const char *host, const char *svc, const char *addr, /* * Shutdown and close the specified socket. - * Returns 0 on success or a negative value on error. + * + * Returns 0 on success, or a negative value on error. * * sock - socket to close */ @@ -82,6 +88,7 @@ extern int net_close(int sock); /* * Wait at most timeout milliseconds for a TCP connection request on * a listener socket to arrive and accept any such request. + * * Returns a newly created socket associated with the accepted TCP * connection, or a negative value on error. * @@ -89,15 +96,16 @@ extern int net_close(int sock); * timeout - timeout in milliseconds * * Note: A time-out condition is considered an error, and errno is set - * to ETIMEDOUT. A negative value for timeout lets tcp_accept() block - * indefinitely. Set timeout to zero for immediate and non-blocking - * operation. + * to ETIMEDOUT. A negative value for timeout will cause tcp_accept() + * to wait indefinitely. Set the timeout to zero for immediate and + * non-blocking operation. */ 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 @@ -107,7 +115,7 @@ extern int tcp_accept(int sock, int timeout); * Note: Depending on the actual value of errnum this function will * return a message based on either strerror_r() or gai_strerror(). */ -extern const char *net_strerror(int errnum, char *buf, size_t len); +extern char *net_strerror(int errnum, char *buf, size_t len); #ifdef cplusplus -- 2.30.2