X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fsessiond-comm%2Fsessiond-comm.c;h=a985dc7fe790994fe37b3d95af93f6bbf0b071f6;hp=58a7ffb509a83fd423bdb418fa354fbdd110ee9f;hb=8684af09caa3ca7014048753361c23d00f8e3be6;hpb=554831e798d0646f5d8c261b6207527c5f839222 diff --git a/src/common/sessiond-comm/sessiond-comm.c b/src/common/sessiond-comm/sessiond-comm.c index 58a7ffb50..a985dc7fe 100644 --- a/src/common/sessiond-comm/sessiond-comm.c +++ b/src/common/sessiond-comm/sessiond-comm.c @@ -17,6 +17,7 @@ */ #define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -373,6 +374,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) {