Signed-off-by: Angus Salkeld asalkeld@redhat.com --- include/qb/qbipcc.h | 8 ++++++++ lib/ipcc.c | 17 +++++++++++++++++ tests/check_ipc.c | 3 +++ 3 files changed, 28 insertions(+)
diff --git a/include/qb/qbipcc.h b/include/qb/qbipcc.h index 0a1124f..98ba456 100644 --- a/include/qb/qbipcc.h +++ b/include/qb/qbipcc.h @@ -199,6 +199,14 @@ void qb_ipcc_context_set(qb_ipcc_connection_t *c, void *context); */ void *qb_ipcc_context_get(qb_ipcc_connection_t *c);
+/** + * Is the connection connected? + * + * @param c connection instance + * @retval QB_TRUE when connected + * @retval QB_FALSE when not connected + */ +int32_t qb_ipcc_is_connected(qb_ipcc_connection_t *c);
/* *INDENT-OFF* */ #ifdef __cplusplus diff --git a/lib/ipcc.c b/lib/ipcc.c index 8ce9ca2..3b44489 100644 --- a/lib/ipcc.c +++ b/lib/ipcc.c @@ -413,3 +413,20 @@ void *qb_ipcc_context_get(struct qb_ipcc_connection *c) } return c->context; } + +int32_t +qb_ipcc_is_connected(qb_ipcc_connection_t *c) +{ + struct qb_ipc_one_way *ow; + + if (c == NULL) { + return QB_FALSE; + } + + ow = _response_sock_one_way_get(c); + if (ow) { + _check_connection_state(c, qb_ipc_us_recv_ready(ow, 0)); + } + + return c->is_connected; +} diff --git a/tests/check_ipc.c b/tests/check_ipc.c index f2124b2..edf7454 100644 --- a/tests/check_ipc.c +++ b/tests/check_ipc.c @@ -659,6 +659,8 @@ test_ipc_server_fail(void) iov[0].iov_len = req_header.size; iov[0].iov_base = &req_header;
+ ck_assert_int_eq(QB_TRUE, qb_ipcc_is_connected(conn)); + res = qb_ipcc_sendv_recv(conn, iov, 1, &res_header, sizeof(struct qb_ipc_response_header), -1); @@ -666,6 +668,7 @@ test_ipc_server_fail(void) * confirm we get -ENOTCONN */ ck_assert_int_eq(res, -ENOTCONN); + ck_assert_int_eq(QB_FALSE, qb_ipcc_is_connected(conn));
qb_ipcc_disconnect(conn); stop_process(pid);
quarterback-devel@lists.fedorahosted.org