[PATCH] Add the event queue length to the connection stats.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)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);
--
1.7.10
12 years
[PATCH] IPC: add a is_connected client side function.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)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);
--
1.7.10
12 years
[PATCH 1/2] docs: clarify the need to use request/response headers
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbipcc.h | 19 +++++++++++++++++++
include/qb/qbipcs.h | 32 ++++++++++++++++++++++++++------
2 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/include/qb/qbipcc.h b/include/qb/qbipcc.h
index a55848f..0a1124f 100644
--- a/include/qb/qbipcc.h
+++ b/include/qb/qbipcc.h
@@ -106,6 +106,10 @@ int32_t qb_ipcc_fc_enable_max_set(qb_ipcc_connection_t * c, uint32_t max);
* @param msg_ptr pointer to a message to send
* @param msg_len the size of the message
* @return (size sent, -errno == error)
+ *
+ * @note the msg_ptr must include a qb_ipc_request_header at
+ * the top of the message. The server will read the size field
+ * to determine how much to recv.
*/
ssize_t qb_ipcc_send(qb_ipcc_connection_t* c, const void *msg_ptr,
size_t msg_len);
@@ -116,6 +120,9 @@ ssize_t qb_ipcc_send(qb_ipcc_connection_t* c, const void *msg_ptr,
* @param iov pointer to an iovec struct to send
* @param iov_len the number of iovecs used
* @return (size sent, -errno == error)
+ *
+ * @note the iov[0] must be a qb_ipc_request_header. The server will
+ * read the size field to determine how much to recv.
*/
ssize_t qb_ipcc_sendv(qb_ipcc_connection_t* c, const struct iovec* iov,
size_t iov_len);
@@ -127,6 +134,9 @@ ssize_t qb_ipcc_sendv(qb_ipcc_connection_t* c, const struct iovec* iov,
* @param msg_len the size of the buffer
* @param ms_timeout max time to wait for a response
* @return (size recv'ed, -errno == error)
+ *
+ * @note that msg_ptr will include a qb_ipc_response_header at
+ * the top of the message.
*/
ssize_t qb_ipcc_recv(qb_ipcc_connection_t* c, void *msg_ptr,
size_t msg_len, int32_t ms_timeout);
@@ -141,6 +151,12 @@ ssize_t qb_ipcc_recv(qb_ipcc_connection_t* c, void *msg_ptr,
* @param msg_len the size of the buffer
* @param ms_timeout max time to wait for a response
*
+ * @note the iov[0] must include a qb_ipc_request_header at
+ * the top of the message. The server will read the size field
+ * to determine how much to recv.
+ * @note that msg_ptr will include a qb_ipc_response_header at
+ * the top of the message.
+ *
* @see qb_ipcc_sendv() qb_ipcc_recv()
*/
ssize_t qb_ipcc_sendv_recv(qb_ipcc_connection_t *c,
@@ -158,6 +174,9 @@ ssize_t qb_ipcc_sendv_recv(qb_ipcc_connection_t *c,
* 0 == no wait, negative == block, positive == wait X ms.
* @param ms_timeout max time to wait for a response
* @return size of the message or error (-errno)
+ *
+ * @note that msg_ptr will include a qb_ipc_response_header at
+ * the top of the message.
*/
ssize_t qb_ipcc_event_recv(qb_ipcc_connection_t* c, void *msg_ptr,
size_t msg_len, int32_t ms_timeout);
diff --git a/include/qb/qbipcs.h b/include/qb/qbipcs.h
index c1aeffe..0a4caed 100644
--- a/include/qb/qbipcs.h
+++ b/include/qb/qbipcs.h
@@ -106,7 +106,8 @@ struct qb_ipcs_poll_handlers {
* or process resource constraints.
* @return 0 to accept or -errno to indicate a failure (sent back to the client)
*/
-typedef int32_t (*qb_ipcs_connection_accept_fn) (qb_ipcs_connection_t *c, uid_t uid, gid_t gid);
+typedef int32_t (*qb_ipcs_connection_accept_fn) (qb_ipcs_connection_t *c,
+ uid_t uid, gid_t gid);
/**
* This is called after a new connection has been created.
@@ -198,7 +199,8 @@ void qb_ipcs_destroy(qb_ipcs_service_t* s);
* @param s service instance
* @param rl the new rate
*/
-void qb_ipcs_request_rate_limit(qb_ipcs_service_t* s, enum qb_ipcs_rate_limit rl);
+void qb_ipcs_request_rate_limit(qb_ipcs_service_t* s,
+ enum qb_ipcs_rate_limit rl);
/**
* Send a response to a incomming request.
@@ -207,8 +209,13 @@ void qb_ipcs_request_rate_limit(qb_ipcs_service_t* s, enum qb_ipcs_rate_limit rl
* @param data the message to send
* @param size the size of the message
* @return size sent or -errno for errors
+ *
+ * @note the data must include a qb_ipc_response_header at
+ * the top of the message. The client will read the size field
+ * to determine how much to recv.
*/
-ssize_t qb_ipcs_response_send(qb_ipcs_connection_t *c, const void *data, size_t size);
+ssize_t qb_ipcs_response_send(qb_ipcs_connection_t *c, const void *data,
+ size_t size);
/**
* Send a response to a incomming request.
@@ -217,8 +224,12 @@ ssize_t qb_ipcs_response_send(qb_ipcs_connection_t *c, const void *data, size_t
* @param iov the iovec struct that points to the message to send
* @param iov_len the number of iovecs.
* @return size sent or -errno for errors
+ *
+ * @note the iov[0] must be a qb_ipc_response_header. The client will
+ * read the size field to determine how much to recv.
*/
-ssize_t qb_ipcs_response_sendv(qb_ipcs_connection_t *c, const struct iovec * iov, size_t iov_len);
+ssize_t qb_ipcs_response_sendv(qb_ipcs_connection_t *c,
+ const struct iovec * iov, size_t iov_len);
/**
* Send an asyncronous event message to the client.
@@ -227,8 +238,13 @@ ssize_t qb_ipcs_response_sendv(qb_ipcs_connection_t *c, const struct iovec * iov
* @param data the message to send
* @param size the size of the message
* @return size sent or -errno for errors
+ *
+ * @note the data must include a qb_ipc_response_header at
+ * the top of the message. The client will read the size field
+ * to determine how much to recv.
*/
-ssize_t qb_ipcs_event_send(qb_ipcs_connection_t *c, const void *data, size_t size);
+ssize_t qb_ipcs_event_send(qb_ipcs_connection_t *c, const void *data,
+ size_t size);
/**
* Send an asyncronous event message to the client.
@@ -237,8 +253,12 @@ ssize_t qb_ipcs_event_send(qb_ipcs_connection_t *c, const void *data, size_t siz
* @param iov the iovec struct that points to the message to send
* @param iov_len the number of iovecs.
* @return size sent or -errno for errors
+ *
+ * @note the iov[0] must be a qb_ipc_response_header. The client will
+ * read the size field to determine how much to recv.
*/
-ssize_t qb_ipcs_event_sendv(qb_ipcs_connection_t *c, const struct iovec * iov, size_t iov_len);
+ssize_t qb_ipcs_event_sendv(qb_ipcs_connection_t *c, const struct iovec * iov,
+ size_t iov_len);
/**
* Increment the connection's reference counter.
--
1.7.10
12 years