summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-08-10 16:00:10 +0200
committerdimitri staessens <[email protected]>2016-08-10 16:00:10 +0200
commit533df37ac3a643017dba96283791d36934e15464 (patch)
treedb9bca81c40407328d9c42d95ac893647b11c3af /src/irmd
parent26b20744a441705accbe550aa0b996f8601a9404 (diff)
parent25e76def21829edef7ef9bca0a028cccfabb944a (diff)
downloadouroboros-533df37ac3a643017dba96283791d36934e15464.tar.gz
ouroboros-533df37ac3a643017dba96283791d36934e15464.zip
Merged in sandervrijders/ouroboros/be-timeout (pull request #202)
lib, irmd, ipcp: Add socket timeout
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/main.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index e36fb98e..aae8a41e 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1477,6 +1477,8 @@ void * mainloop()
irm_msg_t ret_msg = IRM_MSG__INIT;
struct irm_flow * e = NULL;
pid_t * apis = NULL;
+ struct timeval tv = {(SOCKET_TIMEOUT / 1000),
+ (SOCKET_TIMEOUT % 1000) * 1000};
pthread_rwlock_rdlock(&irmd->state_lock);
if (irmd->state != IRMD_RUNNING) {
@@ -1491,6 +1493,10 @@ void * mainloop()
if (cli_sockfd < 0)
continue;
+ if (setsockopt(cli_sockfd, SOL_SOCKET, SO_RCVTIMEO,
+ (void *) &tv, sizeof(tv)))
+ LOG_WARN("Failed to set timeout on socket.");
+
count = read(cli_sockfd, buf, IRM_MSG_BUF_SIZE);
if (count <= 0) {
LOG_ERR("Failed to read from socket.");
@@ -1639,7 +1645,7 @@ void * mainloop()
buffer.len = irm_msg__get_packed_size(&ret_msg);
if (buffer.len == 0) {
- LOG_ERR("Failed to send reply message.");
+ LOG_ERR("Failed to calculate length of reply message.");
if (apis != NULL)
free(apis);
close(cli_sockfd);
@@ -1660,7 +1666,7 @@ void * mainloop()
free(apis);
if (write(cli_sockfd, buffer.data, buffer.len) == -1)
- LOG_ERR("Failed to send reply message.");
+ LOG_WARN("Failed to send reply message.");
free(buffer.data);
close(cli_sockfd);
@@ -1730,11 +1736,8 @@ static struct irm * irm_create()
return NULL;
}
- if (setsockopt(irmd->sockfd,
- SOL_SOCKET,
- SO_RCVTIMEO,
- (char *) &timeout,
- sizeof(timeout)) < 0) {
+ if (setsockopt(irmd->sockfd, SOL_SOCKET, SO_RCVTIMEO,
+ (char *) &timeout, sizeof(timeout)) < 0) {
LOG_ERR("Failed setting socket option.");
irm_destroy();
return NULL;