inet/inet6 sockets: apply timeout
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 8 Aug 2013 09:02:30 +0000 (05:02 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 8 Aug 2013 09:06:01 +0000 (05:06 -0400)
Close #546

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/main.c
src/common/sessiond-comm/inet.c
src/common/sessiond-comm/inet6.c
src/common/sessiond-comm/sessiond-comm.c
src/common/sessiond-comm/sessiond-comm.h
src/common/sessiond-comm/unix.c
src/common/sessiond-comm/unix.h

index e05d72bacb0b9f0ec3278c9c427b6295d7af8347..d22e2a63d7d5d96526a7e93b2c2761a0c0894924 100644 (file)
@@ -1298,11 +1298,17 @@ static void *thread_manage_apps(void *data)
                                                goto error;
                                        }
 
-                                       /* Set socket timeout for both receiving and ending */
+                                       /*
+                                        * Set socket timeout for both receiving and ending.
+                                        * app_socket_timeout is in seconds, whereas
+                                        * lttcomm_setsockopt_rcv_timeout and
+                                        * lttcomm_setsockopt_snd_timeout expect msec as
+                                        * parameter.
+                                        */
                                        (void) lttcomm_setsockopt_rcv_timeout(sock,
-                                                       app_socket_timeout);
+                                                       app_socket_timeout * 1000);
                                        (void) lttcomm_setsockopt_snd_timeout(sock,
-                                                       app_socket_timeout);
+                                                       app_socket_timeout * 1000);
 
                                        DBG("Apps with sock %d added to poll set", sock);
 
index 6d729238a575e8ae149d85a8f25693f7a2554400..eb0c4fde3f6972de1d846020f10aa58a0deaad35 100644 (file)
@@ -57,6 +57,7 @@ LTTNG_HIDDEN
 int lttcomm_create_inet_sock(struct lttcomm_sock *sock, int type, int proto)
 {
        int val = 1, ret;
+       unsigned long timeout;
 
        /* Create server socket */
        if ((sock->fd = socket(PF_INET, type, proto)) < 0) {
@@ -74,6 +75,17 @@ int lttcomm_create_inet_sock(struct lttcomm_sock *sock, int type, int proto)
                PERROR("setsockopt inet");
                goto error;
        }
+       timeout = lttcomm_get_network_timeout();
+       if (timeout) {
+               ret = lttcomm_setsockopt_rcv_timeout(sock->fd, timeout);
+               if (ret) {
+                       goto error;
+               }
+               ret = lttcomm_setsockopt_snd_timeout(sock->fd, timeout);
+               if (ret) {
+                       goto error;
+               }
+       }
 
        return 0;
 
index 52e2f8e5853d9abdb6b6bc059998fb8a92e3057c..5b137c4eb3a73430ad364b9e9acacce4f6126d3b 100644 (file)
@@ -57,6 +57,7 @@ LTTNG_HIDDEN
 int lttcomm_create_inet6_sock(struct lttcomm_sock *sock, int type, int proto)
 {
        int val = 1, ret;
+       unsigned long timeout;
 
        /* Create server socket */
        if ((sock->fd = socket(PF_INET6, type, proto)) < 0) {
@@ -74,6 +75,17 @@ int lttcomm_create_inet6_sock(struct lttcomm_sock *sock, int type, int proto)
                PERROR("setsockopt inet6");
                goto error;
        }
+       timeout = lttcomm_get_network_timeout();
+       if (timeout) {
+               ret = lttcomm_setsockopt_rcv_timeout(sock->fd, timeout);
+               if (ret) {
+                       goto error;
+               }
+               ret = lttcomm_setsockopt_snd_timeout(sock->fd, timeout);
+               if (ret) {
+                       goto error;
+               }
+       }
 
        return 0;
 
index 58a7ffb509a83fd423bdb418fa354fbdd110ee9f..65952b273eaf49c52a17955ab6bda441bd65f554 100644 (file)
@@ -373,6 +373,46 @@ error:
        return NULL;
 }
 
+/*
+ * Set socket receiving timeout.
+ */
+LTTNG_HIDDEN
+int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int msec)
+{
+       int ret;
+       struct timeval tv;
+
+       tv.tv_sec = msec / 1000;
+       tv.tv_usec = (msec % 1000) * 1000;
+
+       ret = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+       if (ret < 0) {
+               PERROR("setsockopt SO_RCVTIMEO");
+       }
+
+       return ret;
+}
+
+/*
+ * Set socket sending timeout.
+ */
+LTTNG_HIDDEN
+int lttcomm_setsockopt_snd_timeout(int sock, unsigned int msec)
+{
+       int ret;
+       struct timeval tv;
+
+       tv.tv_sec = msec / 1000;
+       tv.tv_usec = (msec % 1000) * 1000;
+
+       ret = setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
+       if (ret < 0) {
+               PERROR("setsockopt SO_SNDTIMEO");
+       }
+
+       return ret;
+}
+
 LTTNG_HIDDEN
 void lttcomm_init(void)
 {
index 2450e79ec5bd78379941e9765de694a02df76ed8..c52a6caa0575272788797786b373b85ba286bce9 100644 (file)
@@ -474,6 +474,9 @@ extern void lttcomm_copy_sock(struct lttcomm_sock *dst,
 extern struct lttcomm_relayd_sock *lttcomm_alloc_relayd_sock(
                struct lttng_uri *uri, uint32_t major, uint32_t minor);
 
+extern int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int msec);
+extern int lttcomm_setsockopt_snd_timeout(int sock, unsigned int msec);
+
 extern void lttcomm_init(void);
 /* Get network timeout, in milliseconds */
 extern unsigned long lttcomm_get_network_timeout(void);
index 48fa1049ac99e6d597e8982bceb5e4cfcf9236fe..0d7c95a7637638f066b28f0c2dbe14dc2bbd393d 100644 (file)
@@ -539,45 +539,3 @@ int lttcomm_setsockopt_creds_unix_sock(int sock)
 #else
 #error "Please implement credential support for your OS."
 #endif /* __linux__ */
-
-/*
- * Set socket reciving timeout.
- */
-LTTNG_HIDDEN
-int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int sec)
-{
-       int ret;
-       struct timeval tv;
-
-       tv.tv_sec = sec;
-       tv.tv_usec = 0;
-
-       ret = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
-       if (ret < 0) {
-               PERROR("setsockopt SO_RCVTIMEO");
-               ret = -errno;
-       }
-
-       return ret;
-}
-
-/*
- * Set socket sending timeout.
- */
-LTTNG_HIDDEN
-int lttcomm_setsockopt_snd_timeout(int sock, unsigned int sec)
-{
-       int ret;
-       struct timeval tv;
-
-       tv.tv_sec = sec;
-       tv.tv_usec = 0;
-
-       ret = setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
-       if (ret < 0) {
-               PERROR("setsockopt SO_SNDTIMEO");
-               ret = -errno;
-       }
-
-       return ret;
-}
index 34f156ffd46171298be768abafd1ebca899dcef0..19b91ce40e0dcb689529e886f6737ac9664b8fe8 100644 (file)
@@ -45,7 +45,5 @@ extern ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len,
                lttng_sock_cred *creds);
 
 extern int lttcomm_setsockopt_creds_unix_sock(int sock);
-extern int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int sec);
-extern int lttcomm_setsockopt_snd_timeout(int sock, unsigned int sec);
 
 #endif /* _LTTCOMM_UNIX_H */
This page took 0.03215 seconds and 4 git commands to generate.