Skip to content

Commit

Permalink
IPC: split up the recv into chuncks of 2 seconds.
Browse files Browse the repository at this point in the history
This is because semaphores can't detect the other side has
failed/exited. So we rely on the socket poll to tell us.

Signed-off-by: Angus Salkeld <[email protected]>
  • Loading branch information
asalkeld committed Feb 14, 2012
1 parent b5c66ca commit d633b4e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/ipc_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <semaphore.h>
#endif /* HAVE_POSIX_SHARED_SEMAPHORE */

#define QB_IPC_MAX_WAIT_MS 2000

/*
Client Server
SEND CONN REQ ->
Expand Down
29 changes: 28 additions & 1 deletion lib/ipcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ qb_ipcc_sendv_recv(qb_ipcc_connection_t * c,
void *res_msg, size_t res_len, int32_t ms_timeout)
{
ssize_t res = 0;
int32_t timeout_now;
int32_t timeout_rem = ms_timeout;

if (c == NULL) {
return -EINVAL;
Expand All @@ -243,7 +245,32 @@ qb_ipcc_sendv_recv(qb_ipcc_connection_t * c,
return res;
}

return qb_ipcc_recv(c, res_msg, res_len, ms_timeout);
do {
if (timeout_rem > QB_IPC_MAX_WAIT_MS || ms_timeout == -1) {
timeout_now = QB_IPC_MAX_WAIT_MS;
} else {
timeout_now = timeout_rem;
}

res = qb_ipcc_recv(c, res_msg, res_len, timeout_now);
if (res == -ETIMEDOUT) {
if (ms_timeout < 0) {
res = -EAGAIN;
} else {
timeout_rem -= timeout_now;
if (timeout_rem > 0) {
res = -EAGAIN;
}
}
} else if (res < 0 && res != -EAGAIN) {
errno = -res;
qb_util_perror(LOG_DEBUG,
"qb_ipcc_recv %d timeout:(%d/%d)",
res, timeout_now, timeout_rem);
}
} while (res == -EAGAIN && c->is_connected);

return res;
}

int32_t
Expand Down

0 comments on commit d633b4e

Please sign in to comment.