mirror of
https://salsa.debian.org/ha-team/libqb
synced 2026-08-08 20:07:21 +00:00
ipc example: add -e (events) option
use events instead of responses Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
parent
73731f0643
commit
ad05e6323d
@ -26,7 +26,8 @@
|
||||
#include <qb/qbipcc.h>
|
||||
#include <qb/qblog.h>
|
||||
|
||||
static int do_benchmark = QB_FALSE;
|
||||
static int32_t do_benchmark = QB_FALSE;
|
||||
static int32_t use_events = QB_FALSE;
|
||||
|
||||
#ifndef timersub
|
||||
#define timersub(a, b, result) \
|
||||
@ -130,6 +131,7 @@ do_echo(qb_ipcc_connection_t *conn)
|
||||
struct my_res res;
|
||||
char *newline;
|
||||
int32_t rc;
|
||||
int32_t send_ten_events;
|
||||
|
||||
while (1) {
|
||||
printf("SEND (q or Q to quit) : ");
|
||||
@ -153,13 +155,22 @@ do_echo(qb_ipcc_connection_t *conn)
|
||||
}
|
||||
}
|
||||
|
||||
send_ten_events = (strcasecmp(req.message, "events") == 0);
|
||||
|
||||
if (rc > 0) {
|
||||
rc = qb_ipcc_recv(conn, &res, sizeof(res), -1);
|
||||
if (use_events && !send_ten_events) {
|
||||
printf("waiting for event recv\n");
|
||||
rc = qb_ipcc_event_recv(conn, &res, sizeof(res), -1);
|
||||
} else {
|
||||
printf("waiting for recv\n");
|
||||
rc = qb_ipcc_recv(conn, &res, sizeof(res), -1);
|
||||
}
|
||||
printf("recv %d\n", rc);
|
||||
if (rc < 0) {
|
||||
perror("qb_ipcc_recv");
|
||||
exit(0);
|
||||
}
|
||||
if (strcasecmp(req.message, "events") == 0) {
|
||||
if (send_ten_events) {
|
||||
int32_t i;
|
||||
printf("waiting for 10 events\n");
|
||||
for (i = 0; i < 10; i++) {
|
||||
@ -176,11 +187,25 @@ do_echo(qb_ipcc_connection_t *conn)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
show_usage(const char *name)
|
||||
{
|
||||
printf("usage: \n");
|
||||
printf("%s <options>\n", name);
|
||||
printf("\n");
|
||||
printf(" options:\n");
|
||||
printf("\n");
|
||||
printf(" -h show this help text\n");
|
||||
printf(" -b benchmark\n");
|
||||
printf(" -e use events instead of responses\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
qb_ipcc_connection_t *conn;
|
||||
const char *options = "b";
|
||||
const char *options = "eb";
|
||||
int32_t opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, options)) != -1) {
|
||||
@ -188,7 +213,13 @@ main(int argc, char *argv[])
|
||||
case 'b':
|
||||
do_benchmark = QB_TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
use_events = QB_TRUE;
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
show_usage(argv[0]);
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ static qb_array_t *gio_map;
|
||||
#endif /* HAVE_GLIB */
|
||||
|
||||
static int32_t use_glib = QB_FALSE;
|
||||
static int32_t use_events = QB_FALSE;
|
||||
static qb_loop_t *bms_loop;
|
||||
static qb_ipcs_service_t *s1;
|
||||
|
||||
@ -106,6 +107,7 @@ s1_msg_process_fn(qb_ipcs_connection_t * c, void *data, size_t size)
|
||||
struct iovec iov[2];
|
||||
char resp[100];
|
||||
int32_t sl;
|
||||
int32_t send_ten_events = QB_FALSE;
|
||||
|
||||
hdr = (struct qb_ipc_request_header *)data;
|
||||
if (hdr->id == (QB_IPC_MSG_USER_START + 1)) {
|
||||
@ -130,11 +132,18 @@ s1_msg_process_fn(qb_ipcs_connection_t * c, void *data, size_t size)
|
||||
iov[1].iov_base = resp;
|
||||
response.size += sl;
|
||||
|
||||
res = qb_ipcs_response_sendv(c, iov, 2);
|
||||
send_ten_events = (strcmp(req_pt->message, "events") == 0);
|
||||
|
||||
if (use_events && !send_ten_events) {
|
||||
res = qb_ipcs_event_sendv(c, iov, 2);
|
||||
} else {
|
||||
res = qb_ipcs_response_sendv(c, iov, 2);
|
||||
}
|
||||
if (res < 0) {
|
||||
errno = - res;
|
||||
qb_perror(LOG_ERR, "qb_ipcs_response_send");
|
||||
}
|
||||
if (strcmp(req_pt->message, "events") == 0) {
|
||||
if (send_ten_events) {
|
||||
int32_t i;
|
||||
qb_log(LOG_INFO, "request to send 10 events");
|
||||
for (i = 0; i < 10; i++) {
|
||||
@ -163,8 +172,6 @@ show_usage(const char *name)
|
||||
printf("\n");
|
||||
printf(" -h show this help text\n");
|
||||
printf(" -m use shared memory\n");
|
||||
printf(" -p use posix message queues\n");
|
||||
printf(" -s use sysv message queues\n");
|
||||
printf(" -u use unix sockets\n");
|
||||
printf(" -g use glib mainloop\n");
|
||||
printf(" -e use events\n");
|
||||
@ -306,6 +313,9 @@ main(int32_t argc, char *argv[])
|
||||
case 'g':
|
||||
use_glib = QB_TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
use_events = QB_TRUE;
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
show_usage(argv[0]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user