gitignore [ci skip]
[awesomized/libmemcached] / libtest / client.cc
index e392e6b098332e9da490aded46506a53ff7a7ce7..c536e9dd47f06bbda942fbbaa7644d53dd6e3ad0 100644 (file)
 #include <unistd.h>
 #include <string>
 
+#ifdef HAVE_POLL_H
+# include <poll.h>
+#endif
+
+#ifndef HAVE_MSG_NOSIGNAL
+# define MSG_NOSIGNAL 0
+#endif
 
 namespace libtest {
 
@@ -169,13 +176,29 @@ bool SimpleClient::instance_connect()
         {
           if (connect(sock_fd, address_info_next->ai_addr, address_info_next->ai_addrlen) == SOCKET_ERROR)
           {
+            switch (errno)
+            {
+            case EINTR:
+              close_socket();
+              continue;
+
+            case EINPROGRESS: // nonblocking mode - first return
+            case EALREADY: // nonblocking mode - subsequent returns
+              continue; // Jump to while() and continue on
+
+
+            case ECONNREFUSED:
+            default:
+              break;
+            }
+
             close_socket();
             _error= strerror(errno);
           }
         }
         else
         {
-          fatal_message(strerror(errno));
+          FATAL(strerror(errno));
         }
         address_info_next= address_info_next->ai_next;
       }