Project

General

Profile

Bug #546 » socket-timeout-3.patch

socket-timeout-3.patch - Mathieu Desnoyers, 07/11/2013 01:49 PM

View differences:

src/bin/lttng-sessiond/main.c
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);
src/common/sessiond-comm/inet.c
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) {
......
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;
src/common/sessiond-comm/inet6.c
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) {
......
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;
src/common/sessiond-comm/sessiond-comm.c
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)
{
src/common/sessiond-comm/sessiond-comm.h
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);
src/common/sessiond-comm/unix.c
#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;
}
src/common/sessiond-comm/unix.h
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 */
(15-15/19)