[Icecast-dev] [PATCH 24/31] connection: reorder logic in connection_setup_sockets

Niv Sardi nsardi at smartjog.com
Fri Jul 30 07:54:46 PDT 2010


Make this all more readeable, exit points are now clearer
---
 src/connection.c |   39 +++++++++++++++++++--------------------
 1 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 802a8ad..5024690 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -538,28 +538,27 @@ static connection_t *_accept_connection(int duration)
     ip = (char *)malloc(MAX_ADDR_LEN);
 
     sock = sock_accept(serversock, ip, MAX_ADDR_LEN);
-    if (sock != SOCK_ERROR)
-    {
-        connection_t *con = NULL;
-        /* Make any IPv4 mapped IPv6 address look like a normal IPv4 address */
-        if (strncmp (ip, "::ffff:", 7) == 0)
-            memmove (ip, ip+7, strlen (ip+7)+1);
-
-        if (accept_ip_address (ip)) {
-            con = connection_create (sock, serversock, ip);
-            if (con)
-                return con;
-        }
-        sock_close (sock);
+    if (sock == SOCK_ERROR) {
+        free (ip);
+        if (sock_recoverable(sock_error()))
+            return NULL;
+
+        WARN2("accept() failed with error %d: %s", sock_error(), strerror(sock_error()));
+        thread_sleep (500000);
+        return NULL;
     }
-    else
-    {
-        if (!sock_recoverable(sock_error()))
-        {
-            WARN2("accept() failed with error %d: %s", sock_error(), strerror(sock_error()));
-            thread_sleep (500000);
-        }
+
+    connection_t *con = NULL;
+    /* Make any IPv4 mapped IPv6 address look like a normal IPv4 address */
+    if (strncmp (ip, "::ffff:", 7) == 0)
+        memmove (ip, ip+7, strlen (ip+7)+1);
+
+    if (accept_ip_address (ip)) {
+        con = connection_create (sock, serversock, ip);
+        if (con)
+            return con;
     }
+    sock_close (sock);
     free(ip);
     return NULL;
 }
-- 
1.7.1



More information about the Icecast-dev mailing list