network/socket.cpp: Fix high CPU usage while not in standby
authorMike Looijmans <milo-software@users.sourceforge.net>
Fri, 22 May 2015 18:11:51 +0000 (20:11 +0200)
committerMike Looijmans <milo-software@users.sourceforge.net>
Fri, 22 May 2015 18:26:21 +0000 (20:26 +0200)
The connect method could end up in an "Idle" state with the notifier
still active. The socket would activate but nothing handling it would
read or write it, hence causing a loop.

Fix by calling "close" when connect() fails to reset the socket.

lib/network/socket.cpp

index 638ec6d..5ac70e8 100644 (file)
@@ -236,11 +236,12 @@ int eSocket::connect(struct addrinfo *addr)
 {
        int res;
        struct addrinfo *ptr = addr;
+       close();
        for (ptr = addr; ptr != NULL; ptr = ptr->ai_next)
        {
-               close();
                if (setSocket(socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol), 1) < 0)
                {
+                       /* No need to close, setSocket only fails when socket() already failed */
                        continue;
                }
                mystate = Idle;
@@ -249,6 +250,7 @@ int eSocket::connect(struct addrinfo *addr)
                if ((res < 0) && (errno != EINPROGRESS) && (errno != EINTR))
                {
                        error_(errno);
+                       close(); /* Release and disconnect the notifier */
                        continue;
                }
                if (res < 0)    // EINPROGRESS or EINTR