summaryrefslogtreecommitdiff
path: root/src/lib/sockets.c
diff options
context:
space:
mode:
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)
{