Signed-off-by: Angus Salkeld asalkeld@redhat.com --- lib/ipc_shm.c | 8 ++++---- lib/ipc_us.c | 9 ++------- lib/ipcc.c | 11 ++++++++++- tests/check_ipc.c | 24 ++++++++++++------------ 4 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/lib/ipc_shm.c b/lib/ipc_shm.c index 024194b..1b8fd6e 100644 --- a/lib/ipc_shm.c +++ b/lib/ipc_shm.c @@ -58,7 +58,7 @@ static ssize_t qb_ipc_shm_sendv(struct qb_ipc_one_way *one_way, char *pt = NULL;
if (one_way->u.shm.rb == NULL) { - return -EIDRM; + return -ENOTCONN; }
for (i = 0; i < iov_len; i++) { @@ -88,7 +88,7 @@ static ssize_t qb_ipc_shm_recv(struct qb_ipc_one_way *one_way, { ssize_t res; if (one_way->u.shm.rb == NULL) { - return -EIDRM; + return -ENOTCONN; } res = qb_rb_chunk_read(one_way->u.shm.rb, (void *)msg_ptr, @@ -105,7 +105,7 @@ static ssize_t qb_ipc_shm_peek(struct qb_ipc_one_way *one_way, void **data_out, ssize_t res;
if (one_way->u.shm.rb == NULL) { - return -EIDRM; + return -ENOTCONN; } res = qb_rb_chunk_peek(one_way->u.shm.rb, data_out, @@ -141,7 +141,7 @@ static int32_t qb_ipc_shm_fc_get(struct qb_ipc_one_way *one_way) static ssize_t qb_ipc_shm_q_len_get(struct qb_ipc_one_way *one_way) { if (one_way->u.shm.rb == NULL) { - return -EIDRM; + return -ENOTCONN; } return qb_rb_chunks_used(one_way->u.shm.rb); } diff --git a/lib/ipc_us.c b/lib/ipc_us.c index 231b475..09bdc5c 100644 --- a/lib/ipc_us.c +++ b/lib/ipc_us.c @@ -214,7 +214,7 @@ int32_t qb_ipc_us_recv_ready(struct qb_ipc_one_way *one_way, int32_t ms_timeout) } else if (poll_events == -1) { return -errno; } else if (poll_events == 1 && (ufds.revents & (POLLERR|POLLHUP))) { - return -ESHUTDOWN; + return -ENOTCONN; } return 0; } @@ -233,14 +233,9 @@ ssize_t qb_ipc_us_recv(struct qb_ipc_one_way *one_way, if (result == -1) { return -errno; } -#if defined(QB_SOLARIS) || defined(QB_BSD) || defined(QB_DARWIN) - /* On many OS poll never return POLLHUP or POLLERR. - * EOF is detected when recvmsg return 0. - */ if (result == 0) { - return -errno; //ENOTCONN + return -ENOTCONN; } -#endif if (ctl) { (void)qb_atomic_int_dec_and_test(&ctl->sent); } diff --git a/lib/ipcc.c b/lib/ipcc.c index cab71af..4119152 100644 --- a/lib/ipcc.c +++ b/lib/ipcc.c @@ -129,7 +129,16 @@ ssize_t qb_ipcc_sendv(struct qb_ipcc_connection* c, const struct iovec* iov, ssize_t qb_ipcc_recv(struct qb_ipcc_connection * c, void *msg_ptr, size_t msg_len) { - return c->funcs.recv(&c->response, msg_ptr, msg_len, -1); + int32_t res = 0; + + res = c->funcs.recv(&c->response, msg_ptr, msg_len, 1000); + if (res == -EAGAIN && c->needs_sock_for_poll) { + res = qb_ipc_us_recv_ready(&c->setup, 10); + if (res < 0) { + return res; + } + } + return res; }
ssize_t qb_ipcc_sendv_recv ( diff --git a/tests/check_ipc.c b/tests/check_ipc.c index b2988f3..539e7ee 100644 --- a/tests/check_ipc.c +++ b/tests/check_ipc.c @@ -111,7 +111,6 @@ static int32_t s1_msg_process_fn(qb_ipcs_connection_t *c, perror("qb_ipcs_event_send"); } } else if (req_pt->id == IPC_MSG_REQ_SERVER_FAIL) { - printf("recv'ed server fail - exitting...\n"); exit(0); } return 0; @@ -405,7 +404,6 @@ static void test_ipc_server_fail(void) { struct qb_ipc_request_header req_header; struct qb_ipc_response_header res_header; - size_t size; int32_t res; int32_t try_times = 0; int32_t j; @@ -427,30 +425,32 @@ static void test_ipc_server_fail(void) } while (conn == NULL && c < 5); fail_if(conn == NULL);
+ /* + * tell the server to exit + */ req_header.id = IPC_MSG_REQ_SERVER_FAIL; req_header.size = sizeof(struct qb_ipc_request_header);
repeat_send: - printf("sending server fail\n"); res = qb_ipcc_send(conn, &req_header, req_header.size); try_times++; if (res < 0) { if (res == -EAGAIN && try_times < 10) { goto repeat_send; - } else { - errno = -res; - perror("qb_ipcc_send"); - return res; } + ck_assert_int_eq(res, 0); } - printf("trying to recv from failed server\n");
- repeat_recv: + /* + * try recv from the exit'ed server + */ res = qb_ipcc_recv(conn, &res_header, sizeof(struct qb_ipc_response_header)); - printf("recv %d\n", res); - ck_assert_int_eq(res, 0); + /* + * confirm we get -ENOTCONN + */ + ck_assert_int_eq(res, -ENOTCONN);
qb_ipcc_disconnect(conn); stop_process(pid); @@ -541,7 +541,7 @@ int32_t main(void)
qb_util_set_log_function(ipc_log_fn);
- srunner_run_all(sr, CK_NORMAL); + srunner_run_all(sr, CK_VERBOSE); number_failed = srunner_ntests_failed(sr); srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;