* net: changed order of function definitions; comment reformatting
authorUrban Wallasch <urban.wallasch@freenet.de>
Wed, 23 Oct 2019 20:50:40 +0000 (22:50 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Wed, 23 Oct 2019 20:50:40 +0000 (22:50 +0200)
net/net.c
net/net.h

index 6de3cf0a9f421a45044edfbc08459b7e9ffa617a..af9b43c3548806eff9f3f906674902d85128f0c5 100644 (file)
--- 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) {
index f209dec80d06f0b183dd0e000d0b2dc54ad1b14c..6fe5704005fbc0077f480e8468d02de29cf466e9 100644 (file)
--- a/net/net.h
+++ b/net/net.h
  *
  * 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 <sys/socket.h>
 
+/*
+ * Copy textual description of last error to user supplied buffer.
+ *
+ * Returns a pointer to the buffer.
+ *
+ * errnum - <int> error code returned by any of the above functions
+ * buf    - <char*> user supplied buffer to store the error message
+ * len    - <size_t> 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 - <int> 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 - <int> error code returned by any of the above functions
- * buf    - <char*> user supplied buffer to store the error message
- * len    - <size_t> 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.
  *