From 25e76def21829edef7ef9bca0a028cccfabb944a Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Wed, 10 Aug 2016 14:41:49 +0200 Subject: lib, irmd, ipcp: Add socket timeout This will add a timeout to the socket so that a process won't be blocked by the actions of the process with which it is communicating over the socket. --- src/ipcpd/ipcp.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/ipcpd') diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index a9f2b77b..784d845a 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -113,6 +113,9 @@ void * ipcp_main_loop(void * o) char * sock_path; + struct timeval tv = {(SOCKET_TIMEOUT / 1000), + (SOCKET_TIMEOUT % 1000) * 1000}; + if (_ipcp == NULL) { LOG_ERR("Invalid ipcp struct."); return (void *) 1; @@ -141,6 +144,10 @@ void * ipcp_main_loop(void * o) break; } + if (setsockopt(lsockfd, SOL_SOCKET, SO_RCVTIMEO, + (void *) &tv, sizeof(tv))) + LOG_WARN("Failed to set timeout on socket."); + pthread_cleanup_push(close_ptr, (void *) &lsockfd); count = read(lsockfd, buf, IPCP_MSG_BUF_SIZE); -- cgit v1.2.3