High: ipcs: Api function allowing server to retrieve client connection's ipc buffer size

This commit is contained in:
David Vossel 2013-10-08 16:56:38 -05:00
parent a8852fc481
commit 2b11b783c7
3 changed files with 39 additions and 0 deletions

View File

@ -260,6 +260,10 @@ ssize_t qb_ipcs_response_send(qb_ipcs_connection_t *c, const void *data,
*
* @note the iov[0] must be a qb_ipc_response_header. The client will
* read the size field to determine how much to recv.
*
* @note When send returns -EMSGSIZE, this means the msg is too
* large and will never succeed. To determine the max msg size
* a client can be sent, use qb_ipcs_connection_get_buffer_size()
*/
ssize_t qb_ipcs_response_sendv(qb_ipcs_connection_t *c,
const struct iovec * iov, size_t iov_len);
@ -275,6 +279,10 @@ ssize_t qb_ipcs_response_sendv(qb_ipcs_connection_t *c,
* @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.
*
* @note When send returns -EMSGSIZE, this means the msg is too
* large and will never succeed. To determine the max msg size
* a client can be sent, use qb_ipcs_connection_get_buffer_size()
*/
ssize_t qb_ipcs_event_send(qb_ipcs_connection_t *c, const void *data,
size_t size);
@ -289,6 +297,10 @@ ssize_t qb_ipcs_event_send(qb_ipcs_connection_t *c, const void *data,
*
* @note the iov[0] must be a qb_ipc_response_header. The client will
* read the size field to determine how much to recv.
*
* @note When send returns -EMSGSIZE, this means the msg is too
* large and will never succeed. To determine the max msg size
* a client can be sent, use qb_ipcs_connection_get_buffer_size()
*/
ssize_t qb_ipcs_event_sendv(qb_ipcs_connection_t *c, const struct iovec * iov,
size_t iov_len);
@ -423,6 +435,14 @@ qb_ipcs_connection_t * qb_ipcs_connection_next_get(qb_ipcs_service_t* pt,
void qb_ipcs_connection_auth_set(qb_ipcs_connection_t *conn, uid_t uid,
gid_t gid, mode_t mode);
/**
* Retrieve the connection ipc buffer size. This reflects the
* largest size msg that can be sent or received.
*
* @param conn connection instance
* @return msg size in bytes, negative value on error.
*/
int32_t qb_ipcs_connection_get_buffer_size(qb_ipcs_connection_t *conn);
/* *INDENT-OFF* */
#ifdef __cplusplus

View File

@ -941,3 +941,16 @@ qb_ipcs_connection_auth_set(qb_ipcs_connection_t *c, uid_t uid,
c->auth.mode = mode;
}
}
int32_t
qb_ipcs_connection_get_buffer_size(qb_ipcs_connection_t *c)
{
if (c == NULL) {
return -EINVAL;
}
/* request, response, and event shoud all have the same
* buffer size allocated. It doesn't matter which we return
* here. */
return c->response.max_msg_size;
}

View File

@ -312,6 +312,8 @@ s1_connection_destroyed(qb_ipcs_connection_t *c)
static void
s1_connection_created(qb_ipcs_connection_t *c)
{
int32_t max = MAX_MSG_SIZE;
if (send_event_on_created) {
struct qb_ipc_response_header response;
int32_t res;
@ -333,6 +335,10 @@ s1_connection_created(qb_ipcs_connection_t *c)
memcpy(context, "test", 4);
qb_ipcs_context_set(c, context);
}
ck_assert_int_eq(max, qb_ipcs_connection_get_buffer_size(c));
}
static void