diff options
author | Sander Vrijders <[email protected]> | 2016-08-10 14:41:49 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-08-10 15:59:27 +0200 |
commit | 25e76def21829edef7ef9bca0a028cccfabb944a (patch) | |
tree | db9bca81c40407328d9c42d95ac893647b11c3af /src/irmd/main.c | |
parent | 26b20744a441705accbe550aa0b996f8601a9404 (diff) | |
download | ouroboros-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/irmd/main.c')
-rw-r--r-- | src/irmd/main.c | 17 |
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; |