summaryrefslogtreecommitdiff
path: root/src/lib/sockets.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-08-10 14:41:49 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-08-10 15:59:27 +0200
commit25e76def21829edef7ef9bca0a028cccfabb944a (patch)
treedb9bca81c40407328d9c42d95ac893647b11c3af /src/lib/sockets.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/sockets.c')
-rw-r--r--src/lib/sockets.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index 0d93c0a9..751c61b2 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -35,6 +35,7 @@
#include <stdlib.h>
#include <pthread.h>
#include <stdbool.h>
+#include <sys/time.h>
int client_socket_open(char * file_name)
{
@@ -106,17 +107,25 @@ void close_ptr(void * o)
close(*(int *) o);
}
-irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)
+static irm_msg_t * send_recv_irm_msg_timed(irm_msg_t * msg,
+ bool timed)
{
int sockfd;
buffer_t buf;
ssize_t count = 0;
irm_msg_t * recv_msg = NULL;
+ struct timeval tv = {(SOCKET_TIMEOUT / 1000),
+ (SOCKET_TIMEOUT % 1000) * 1000};
sockfd = client_socket_open(IRM_SOCK_PATH);
if (sockfd < 0)
return NULL;
+ if (timed)
+ if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO,
+ (void *) &tv, sizeof(tv)))
+ LOG_WARN("Failed to set timeout on socket.");
+
buf.len = irm_msg__get_packed_size(msg);
if (buf.len == 0) {
close(sockfd);
@@ -147,6 +156,11 @@ irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)
return recv_msg;
}
+irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)
+{ return send_recv_irm_msg_timed(msg, true); }
+
+irm_msg_t * send_recv_irm_msg_b(irm_msg_t * msg)
+{ return send_recv_irm_msg_timed(msg, false); }
char * ipcp_sock_path(pid_t api)
{