Add a timeout to UST application socket
[lttng-tools.git] / src / common / sessiond-comm / unix.c
index 9ef04ee0df1943ce41b4ca886ee2913d27d21619..2f79f3a280a123bd85a861ff039f72e5e4c6064c 100644 (file)
@@ -523,3 +523,45 @@ int lttcomm_setsockopt_creds_unix_sock(int sock)
 #else
 #error "Please implement credential support for your OS."
 #endif /* __linux__ */
+
+/*
+ * Set socket reciving timeout.
+ */
+__attribute__((visibility("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.
+ */
+__attribute__((visibility("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;
+}
This page took 0.025267 seconds and 5 git commands to generate.