Fix: set errno with value from SO_ERROR on error.
[lttng-tools.git] / src / common / sessiond-comm / inet.c
index 84bee5bd99142970ece0b1e1a1e9c2a0be10c720..ed7f5dc165e1b3961a2f53ef3107a0f54db85472 100644 (file)
 #include <poll.h>
 
 #include <common/common.h>
+#include <common/time.h>
 
 #include "inet.h"
 
-#define MSEC_PER_SEC   1000
-#define NSEC_PER_MSEC  1000000
 #define RECONNECT_DELAY        200     /* ms */
 
 /*
@@ -177,6 +176,8 @@ int connect_with_timeout(struct lttcomm_sock *sock)
                goto success;
        }
 
+       DBG("Asynchronous connect for sock %d, performing polling with"
+                       " timeout: %lums", sock->fd, timeout);
        /*
         * Perform poll loop following EINPROGRESS recommendation from
         * connect(2) man page.
@@ -203,12 +204,15 @@ int connect_with_timeout(struct lttcomm_sock *sock)
                        ret = getsockopt(sock->fd, SOL_SOCKET,
                                SO_ERROR, &optval, &optval_len);
                        if (ret) {
+                               PERROR("getsockopt");
                                goto error;
                        }
                        if (!optval) {
                                connect_ret = 0;
                                goto success;
                        } else {
+                               /* Get actual connect() errno from opt_val */
+                               errno = optval;
                                goto error;
                        }
                }
This page took 0.023573 seconds and 4 git commands to generate.