socket-util: Avoid using SO_ERROR.
[sliver-openvswitch.git] / lib / socket-util.c
index 4edf956..4843cc5 100644 (file)
@@ -221,6 +221,7 @@ get_socket_error(int fd)
 int
 check_connection_completion(int fd)
 {
+    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10);
     struct pollfd pfd;
     int retval;
 
@@ -230,9 +231,17 @@ check_connection_completion(int fd)
         retval = poll(&pfd, 1, 0);
     } while (retval < 0 && errno == EINTR);
     if (retval == 1) {
-        return get_socket_error(fd);
+        if (pfd.revents & POLLERR) {
+            ssize_t n = send(fd, "", 1, MSG_DONTWAIT);
+            if (n < 0) {
+                return errno;
+            } else {
+                VLOG_ERR_RL(&rl, "poll return POLLERR but send succeeded");
+                return EPROTO;
+            }
+        }
+        return 0;
     } else if (retval < 0) {
-        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10);
         VLOG_ERR_RL(&rl, "poll: %s", strerror(errno));
         return errno;
     } else {