Signed-off-by: Angus Salkeld asalkeld@redhat.com --- include/qb/qbipcs.h | 1 + lib/ipcs.c | 7 +++++++ tests/check_ipc.c | 16 ++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/include/qb/qbipcs.h b/include/qb/qbipcs.h index 0a4caed..4f2934e 100644 --- a/include/qb/qbipcs.h +++ b/include/qb/qbipcs.h @@ -71,6 +71,7 @@ struct qb_ipcs_connection_stats { uint64_t recv_retries; int32_t flow_control_state; uint64_t flow_control_count; + uint32_t event_q_length; };
typedef int32_t (*qb_ipcs_dispatch_fn_t) (int32_t fd, int32_t revents, diff --git a/lib/ipcs.c b/lib/ipcs.c index 33a887b..c30a405 100644 --- a/lib/ipcs.c +++ b/lib/ipcs.c @@ -754,7 +754,14 @@ qb_ipcs_connection_stats_get(qb_ipcs_connection_t * c, if (c == NULL) { return -EINVAL; } + memcpy(stats, &c->stats, sizeof(struct qb_ipcs_connection_stats)); + + if (c->service->funcs.q_len_get) { + stats->event_q_length = c->service->funcs.q_len_get(&c->event); + } else { + stats->event_q_length = 0; + } if (clear_after_read) { memset(&c->stats, 0, sizeof(struct qb_ipcs_connection_stats)); c->stats.client_pid = c->pid; diff --git a/tests/check_ipc.c b/tests/check_ipc.c index edf7454..02f18c9 100644 --- a/tests/check_ipc.c +++ b/tests/check_ipc.c @@ -47,6 +47,7 @@ enum my_msg_ids { IPC_MSG_REQ_SERVER_FAIL, IPC_MSG_RES_SERVER_FAIL, }; +#define NUM_BULK_EVENTS 10
/* Test Cases * @@ -112,18 +113,24 @@ s1_msg_process_fn(qb_ipcs_connection_t *c, } } else if (req_pt->id == IPC_MSG_REQ_BULK_EVENTS) { int32_t m; + struct qb_ipcs_connection_stats stats; + response.size = sizeof(struct qb_ipc_response_header); response.id = IPC_MSG_RES_BULK_EVENTS; response.error = 0; - qb_ipcs_response_send(c, &response, response.size);
- for (m = 0; m < 100; m++) { + for (m = 0; m < NUM_BULK_EVENTS; m++) { res = qb_ipcs_event_send(c, &response, sizeof(response)); if (res < 0) { qb_perror(LOG_INFO, "qb_ipcs_event_send"); } } + qb_ipcs_connection_stats_get(c, &stats, QB_FALSE); + ck_assert_int_eq(stats.event_q_length, NUM_BULK_EVENTS); + qb_ipcs_response_send(c, &response, response.size); + + } else if (req_pt->id == IPC_MSG_REQ_SERVER_FAIL) { exit(0); } @@ -554,6 +561,7 @@ END_TEST
static int32_t events_received;
+ static int32_t count_bulk_events(int32_t fd, int32_t revents, void *data) { @@ -561,7 +569,7 @@ count_bulk_events(int32_t fd, int32_t revents, void *data)
events_received++;
- if (events_received >= 100) { + if (events_received >= NUM_BULK_EVENTS) { qb_loop_stop(cl); return -1; } @@ -608,7 +616,7 @@ test_ipc_bulk_events(void) ck_assert_int_eq(res, sizeof(struct qb_ipc_response_header));
qb_loop_run(cl); - ck_assert_int_eq(events_received, 100); + ck_assert_int_eq(events_received, NUM_BULK_EVENTS);
qb_ipcc_disconnect(conn); stop_process(pid);