This is an example of how to use the client.
#include "os_base.h"
#include <signal.h>
static int alarm_notice;
#define ONE_MEG 1048576
static char *data;
struct my_req {
char message[256];
};
struct my_res {
char message[256];
};
static void sigalrm_handler (int num)
{
alarm_notice = 1;
}
static void
{
struct iovec iov[2];
ssize_t res;
int write_count = 0;
float secs;
alarm_notice = 0;
hdr.size = write_size;
iov[0].iov_base = &hdr;
iov[1].iov_base = data;
alarm (10);
do {
if (res == write_size) {
write_count++;
}
} while (alarm_notice == 0 && (res == write_size || res == -EAGAIN));
if (res < 0) {
perror("qb_ipcc_sendv");
}
printf ("%5d messages sent ", write_count);
printf ("%5d bytes per write ", write_size);
printf ("%7.3f Seconds runtime ", secs);
printf ("%9.3f TP/s ",
((float)write_count) / secs);
printf ("%7.3f MB/s.\n",
((float)write_count) * ((float)write_size) / secs);
}
static void
{
ssize_t size = 64;
int i;
signal (SIGALRM, sigalrm_handler);
for (i = 0; i < 10; i++) {
_benchmark (conn, size);
signal (SIGALRM, sigalrm_handler);
size *= 5;
if (size >= (ONE_MEG - 100)) {
break;
}
}
}
static void
{
struct my_req req;
struct my_res res;
char *newline;
int32_t rc;
int32_t send_ten_events;
while (1) {
printf("SEND (q or Q to quit) : ");
if (fgets(req.message, 256, stdin) == NULL) {
continue;
}
newline = strrchr(req.message, '\n');
if (newline) {
*newline = '\0';
}
if (strcasecmp(req.message, "q") == 0) {
break;
} else {
req.hdr.size = sizeof(struct my_req);
if (rc < 0) {
perror("qb_ipcc_send");
exit(0);
}
}
send_ten_events = (strcasecmp(req.message, "events") == 0);
if (rc > 0) {
if (use_events && !send_ten_events) {
printf("waiting for event recv\n");
} else {
printf("waiting for recv\n");
}
printf("recv %d\n", rc);
if (rc < 0) {
perror("qb_ipcc_recv");
exit(0);
}
if (send_ten_events) {
int32_t i;
printf("waiting for 10 events\n");
for (i = 0; i < 10; i++) {
if (rc < 0) {
perror("qb_ipcc_event_recv");
} else {
printf("got event %d rc:%d\n", i, rc);
}
}
}
printf("Response[%d]: %s \n", res.hdr.id, res.message);
}
}
}
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[])
{
const char *options = "ebh";
int32_t opt;
while ((opt = getopt(argc, argv, options)) != -1) {
switch (opt) {
case 'b':
break;
case 'e':
break;
case 'h':
default:
show_usage(argv[0]);
exit(0);
break;
}
}
if (conn == NULL) {
perror("qb_ipcc_connect");
exit(1);
}
if (do_benchmark) {
do_throughput_benchmark(conn);
} else {
do_echo(conn);
}
free(data);
return EXIT_SUCCESS;
}
These are some convience macros and defines.
#define QB_FALSE
Definition: qbdefs.h:47
#define QB_TRUE
Definition: qbdefs.h:48
#define QB_IPC_MSG_USER_START
Definition: qbipc_common.h:60
void qb_ipcc_disconnect(qb_ipcc_connection_t *c)
Disconnect an IPC connection.
struct qb_ipcc_connection qb_ipcc_connection_t
Definition: qbipcc.h:62
qb_ipcc_connection_t * qb_ipcc_connect(const char *name, size_t max_msg_size)
Create a connection to an IPC service.
ssize_t qb_ipcc_send(qb_ipcc_connection_t *c, const void *msg_ptr, size_t msg_len)
Send a message.
ssize_t qb_ipcc_event_recv(qb_ipcc_connection_t *c, void *msg_ptr, size_t msg_len, int32_t ms_timeout)
Receive an event.
int32_t qb_ipcc_get_buffer_size(qb_ipcc_connection_t *c)
What is the actual buffer size used after the connection.
ssize_t qb_ipcc_recv(qb_ipcc_connection_t *c, void *msg_ptr, size_t msg_len, int32_t ms_timeout)
Receive a response.
ssize_t qb_ipcc_sendv(qb_ipcc_connection_t *c, const struct iovec *iov, size_t iov_len)
Send a message (iovec).
The logging API provides four main parts (basics, filtering, threading & blackbox).
@ QB_LOG_FILTER_ADD
Definition: qblog.h:595
void qb_log_format_set(int32_t t, const char *format)
Set the format specifiers.
void qb_log_init(const char *name, int32_t facility, uint8_t priority)
Init the logging system.
@ QB_LOG_SYSLOG
Definition: qblog.h:551
@ QB_LOG_STDERR
Definition: qblog.h:552
int32_t qb_log_filter_ctl(int32_t value, enum qb_log_filter_conf c, enum qb_log_filter_type type, const char *text, uint8_t low_priority)
This allows you modify the 'tags' and 'targets' callsite fields at runtime.
@ QB_LOG_FILTER_FILE
Definition: qblog.h:586
@ QB_LOG_CONF_ENABLED
Definition: qblog.h:573
int32_t qb_log_ctl(int32_t target, enum qb_log_conf conf_type, int32_t arg)
Main logging control function.
void qb_log_fini(void)
Logging system finalization function.
#define LOG_TRACE
Definition: qblog.h:265
These are some convience functions used throughout libqb.
void qb_util_stopwatch_start(qb_util_stopwatch_t *sw)
Start the stopwatch.
float qb_util_stopwatch_sec_elapsed_get(qb_util_stopwatch_t *sw)
Get the elapsed time in seconds.
void qb_util_stopwatch_stop(qb_util_stopwatch_t *sw)
Stop the stopwatch.
struct qb_util_stopwatch qb_util_stopwatch_t
Definition: qbutil.h:198
qb_util_stopwatch_t * qb_util_stopwatch_create(void)
Create a Stopwatch (to time operations)