summaryrefslogtreecommitdiff
path: root/src/lib/ipcp.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-08-10 14:41:49 +0200
committerSander Vrijders <[email protected]>2016-08-10 15:59:27 +0200
commit25e76def21829edef7ef9bca0a028cccfabb944a (patch)
treedb9bca81c40407328d9c42d95ac893647b11c3af /src/lib/ipcp.c
parent26b20744a441705accbe550aa0b996f8601a9404 (diff)
downloadouroboros-25e76def21829edef7ef9bca0a028cccfabb944a.tar.gz
ouroboros-25e76def21829edef7ef9bca0a028cccfabb944a.zip
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.
Diffstat (limited to 'src/lib/ipcp.c')
-rw-r--r--src/lib/ipcp.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c
index 9ff05e7b..bdc980f9 100644
--- a/src/lib/ipcp.c
+++ b/src/lib/ipcp.c
@@ -37,6 +37,8 @@
#include <pthread.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/socket.h>
+#include <sys/time.h>
static void close_ptr(void * o)
{
@@ -51,6 +53,8 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t api,
char * sock_path = NULL;
ssize_t count = 0;
ipcp_msg_t * recv_msg = NULL;
+ struct timeval tv = {(SOCKET_TIMEOUT / 1000),
+ (SOCKET_TIMEOUT % 1000) * 1000};
sock_path = ipcp_sock_path(api);
if (sock_path == NULL)
@@ -62,6 +66,10 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t api,
return NULL;
}
+ if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO,
+ (void *) &tv, sizeof(tv)))
+ LOG_WARN("Failed to set timeout on socket.");
+
free(sock_path);
buf.len = ipcp_msg__get_packed_size(msg);