Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
examples/ipcclient.c | 10 +++-----
examples/ipcserver.c | 67 +++++++++++++++++++++++++-------------------------
examples/mapnotify.c | 10 +++++---
examples/simplelog.c | 44 +++++++++++++++++----------------
examples/tcpclient.c | 7 +++---
examples/tcpserver.c | 35 +++++++++-----------------
6 files changed, 80 insertions(+), 93 deletions(-)
diff --git a/examples/ipcclient.c b/examples/ipcclient.c
index bc16635..412e6a8 100644
--- a/examples/ipcclient.c
+++ b/examples/ipcclient.c
@@ -50,8 +50,7 @@ main(int argc, char *argv[])
qb_log_init("ipcclient", LOG_USER, LOG_TRACE);
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
- QB_LOG_FILTER_FILE, "*",
- LOG_TRACE);
+ QB_LOG_FILTER_FILE, "*", LOG_TRACE);
qb_log_format_set(QB_LOG_STDERR, "%f:%l [%p] %b");
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
@@ -61,7 +60,7 @@ main(int argc, char *argv[])
exit(1);
}
- while(1) {
+ while (1) {
printf("SEND (q or Q to quit) : ");
if (fgets(req.message, 256, stdin) == NULL) {
continue;
@@ -83,9 +82,7 @@ main(int argc, char *argv[])
}
if (rc > 0) {
- rc = qb_ipcc_recv(conn,
- &res,
- sizeof(res), -1);
+ rc = qb_ipcc_recv(conn, &res, sizeof(res), -1);
if (rc < 0) {
perror("qb_ipcc_recv");
}
@@ -96,4 +93,3 @@ main(int argc, char *argv[])
qb_ipcc_disconnect(conn);
return EXIT_SUCCESS;
}
-
diff --git a/examples/ipcserver.c b/examples/ipcserver.c
index 7e62fc7..e863690 100644
--- a/examples/ipcserver.c
+++ b/examples/ipcserver.c
@@ -35,10 +35,10 @@ static qb_array_t *gio_map;
static int32_t use_glib = QB_FALSE;
static qb_loop_t *bms_loop;
-static qb_ipcs_service_t* s1;
+static qb_ipcs_service_t *s1;
static int32_t
-s1_connection_accept_fn(qb_ipcs_connection_t *c, uid_t uid, gid_t gid)
+s1_connection_accept_fn(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
{
#if 0
if (uid == 0 && gid == 0) {
@@ -52,34 +52,33 @@ s1_connection_accept_fn(qb_ipcs_connection_t *c, uid_t uid, gid_t
gid)
#endif
}
-static void
-s1_connection_created_fn(qb_ipcs_connection_t *c)
+static void
+s1_connection_created_fn(qb_ipcs_connection_t * c)
{
struct qb_ipcs_stats srv_stats;
qb_ipcs_stats_get(s1, &srv_stats, QB_FALSE);
qb_log(LOG_INFO, "Connection created (active:%d, closed:%d)",
- srv_stats.active_connections,
- srv_stats.closed_connections);
+ srv_stats.active_connections, srv_stats.closed_connections);
}
-static void
-s1_connection_destroyed_fn(qb_ipcs_connection_t *c)
+static void
+s1_connection_destroyed_fn(qb_ipcs_connection_t * c)
{
qb_log(LOG_INFO, "Connection about to be freed");
}
-static int32_t
-s1_connection_closed_fn(qb_ipcs_connection_t *c)
+static int32_t
+s1_connection_closed_fn(qb_ipcs_connection_t * c)
{
struct qb_ipcs_connection_stats stats;
struct qb_ipcs_stats srv_stats;
qb_ipcs_stats_get(s1, &srv_stats, QB_FALSE);
qb_ipcs_connection_stats_get(c, &stats, QB_FALSE);
- qb_log(LOG_INFO, "Connection to pid:%d destroyed (active:%d, closed:%d)",
- stats.client_pid,
- srv_stats.active_connections,
+ qb_log(LOG_INFO,
+ "Connection to pid:%d destroyed (active:%d, closed:%d)",
+ stats.client_pid, srv_stats.active_connections,
srv_stats.closed_connections);
qb_log(LOG_DEBUG, " Requests %"PRIu64"", stats.requests);
@@ -92,11 +91,11 @@ s1_connection_closed_fn(qb_ipcs_connection_t *c)
return 0;
}
-static int32_t
-s1_msg_process_fn(qb_ipcs_connection_t *c,
- void *data, size_t size)
+static int32_t
+s1_msg_process_fn(qb_ipcs_connection_t * c, void *data, size_t size)
{
- struct qb_ipc_request_header *req_pt = (struct qb_ipc_request_header *)data;
+ struct qb_ipc_request_header *req_pt =
+ (struct qb_ipc_request_header *)data;
struct qb_ipc_response_header response;
ssize_t res;
struct iovec iov[2];
@@ -121,7 +120,7 @@ s1_msg_process_fn(qb_ipcs_connection_t *c,
return 0;
}
-static void
+static void
sigusr1_handler(int32_t num)
{
qb_log(LOG_DEBUG, "(%d)", num);
@@ -129,7 +128,7 @@ sigusr1_handler(int32_t num)
exit(0);
}
-static void
+static void
show_usage(const char *name)
{
printf("usage: \n");
@@ -151,13 +150,13 @@ struct gio_to_qb_poll {
gboolean is_used;
GIOChannel *channel;
int32_t events;
- void * data;
+ void *data;
qb_ipcs_dispatch_fn_t fn;
enum qb_loop_priority p;
};
static gboolean
-gio_read_socket (GIOChannel *gio, GIOCondition condition, gpointer data)
+gio_read_socket(GIOChannel * gio, GIOCondition condition, gpointer data)
{
struct gio_to_qb_poll *adaptor = (struct gio_to_qb_poll *)data;
gint fd = g_io_channel_unix_get_fd(gio);
@@ -165,15 +164,15 @@ gio_read_socket (GIOChannel *gio, GIOCondition condition, gpointer
data)
return (adaptor->fn(fd, condition, adaptor->data) == 0);
}
-static int32_t
+static int32_t
my_g_dispatch_add(enum qb_loop_priority p, int32_t fd, int32_t evts,
- void *data, qb_ipcs_dispatch_fn_t fn)
+ void *data, qb_ipcs_dispatch_fn_t fn)
{
struct gio_to_qb_poll *adaptor;
GIOChannel *channel;
int32_t res = 0;
- res = qb_array_index(gio_map, fd, (void**)&adaptor);
+ res = qb_array_index(gio_map, fd, (void **)&adaptor);
if (res < 0) {
return res;
}
@@ -199,7 +198,7 @@ my_g_dispatch_add(enum qb_loop_priority p, int32_t fd, int32_t evts,
static int32_t
my_g_dispatch_mod(enum qb_loop_priority p, int32_t fd, int32_t evts,
- void *data, qb_ipcs_dispatch_fn_t fn)
+ void *data, qb_ipcs_dispatch_fn_t fn)
{
return 0;
}
@@ -208,7 +207,7 @@ static int32_t
my_g_dispatch_del(int32_t fd)
{
struct gio_to_qb_poll *adaptor;
- if (qb_array_index(gio_map, fd, (void**)&adaptor) == 0) {
+ if (qb_array_index(gio_map, fd, (void **)&adaptor) == 0) {
g_io_channel_unref(adaptor->channel);
adaptor->is_used = FALSE;
}
@@ -216,7 +215,7 @@ my_g_dispatch_del(int32_t fd)
}
#endif /* HAVE_GLIB */
-static int32_t
+static int32_t
my_job_add(enum qb_loop_priority p, void *data, qb_loop_job_dispatch_fn fn)
{
return qb_loop_job_add(bms_loop, p, data, fn);
@@ -224,14 +223,14 @@ my_job_add(enum qb_loop_priority p, void *data,
qb_loop_job_dispatch_fn fn)
static int32_t
my_dispatch_add(enum qb_loop_priority p, int32_t fd, int32_t evts,
- void *data, qb_ipcs_dispatch_fn_t fn)
+ void *data, qb_ipcs_dispatch_fn_t fn)
{
return qb_loop_poll_add(bms_loop, p, fd, evts, data, fn);
}
-static int32_t
+static int32_t
my_dispatch_mod(enum qb_loop_priority p, int32_t fd, int32_t evts,
- void *data, qb_ipcs_dispatch_fn_t fn)
+ void *data, qb_ipcs_dispatch_fn_t fn)
{
return qb_loop_poll_mod(bms_loop, p, fd, evts, data, fn);
}
@@ -296,10 +295,9 @@ main(int32_t argc, char *argv[])
}
signal(SIGINT, sigusr1_handler);
- qb_log_init("ipcserver", LOG_USER, LOG_WARNING);
+ qb_log_init("ipcserver", LOG_USER, LOG_TRACE);
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
- QB_LOG_FILTER_FILE, __FILE__,
- LOG_DEBUG);
+ QB_LOG_FILTER_FILE, __FILE__, LOG_TRACE);
qb_log_format_set(QB_LOG_STDERR, "%f:%l [%p] %b");
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
@@ -321,7 +319,8 @@ main(int32_t argc, char *argv[])
qb_ipcs_run(s1);
g_main_loop_run(glib_loop);
#else
- qb_log(LOG_ERR, "You don't seem to have glib-devel installed.\n");
+ qb_log(LOG_ERR,
+ "You don't seem to have glib-devel installed.\n");
#endif
}
return EXIT_SUCCESS;
diff --git a/examples/mapnotify.c b/examples/mapnotify.c
index e883852..daf5164 100644
--- a/examples/mapnotify.c
+++ b/examples/mapnotify.c
@@ -26,7 +26,8 @@
#include <qb/qbmap.h>
static void
-notify_fn(uint32_t event, char* key, void* old_value, void* value, void* user_data)
+notify_fn(uint32_t event, char *key, void *old_value, void *value,
+ void *user_data)
{
if (event == QB_MAP_NOTIFY_FREE) {
fprintf(stderr, "Notify[FREE] %s [%d]\n",
@@ -44,13 +45,14 @@ notify_fn(uint32_t event, char* key, void* old_value, void* value,
void* user_da
fprintf(stderr, " value = [%d]\n", *(int *)value);
}
if (old_value != NULL) {
- fprintf(stderr, " old value = [%d]\n", *(int *)old_value);
+ fprintf(stderr, " old value = [%d]\n",
+ *(int *)old_value);
}
}
}
static void
-add_cs_keys(qb_map_t *m)
+add_cs_keys(qb_map_t * m)
{
qb_map_put(m, "compatibility", strdup("none"));
qb_map_put(m, "totem.version", strdup("2"));
@@ -197,7 +199,7 @@ main(void)
iter = qb_map_pref_iter_create(trie, "test.");
while ((key = qb_map_iter_next(iter, &val)) != NULL) {
- fprintf(stderr,"Iter %s [%d]\n", key, *(int*)val);
+ fprintf(stderr, "Iter %s [%d]\n", key, *(int *)val);
qb_map_rm(trie, key);
}
qb_map_iter_free(iter);
diff --git a/examples/simplelog.c b/examples/simplelog.c
index d5fbc0a..8fb0941 100644
--- a/examples/simplelog.c
+++ b/examples/simplelog.c
@@ -31,16 +31,17 @@
static int32_t _log_priority = LOG_WARNING;
-static void func_one(void)
+static void
+func_one(void)
{
- FILE* fd;
+ FILE *fd;
qb_enter();
qb_logt(LOG_DEBUG, MY_TAG_TWO, "arf arf?");
- qb_logt(LOG_CRIT, MY_TAG_THREE, "arrrg!");
- qb_logt(134, MY_TAG_THREE, "big priority");
- qb_logt(LOG_ERR, MY_TAG_THREE, "oops, I did it again");
- qb_log(LOG_INFO, "are you aware ...");
+ qb_logt(LOG_CRIT, MY_TAG_THREE, "arrrg!");
+ qb_logt(134, MY_TAG_THREE, "big priority");
+ qb_logt(LOG_ERR, MY_TAG_THREE, "oops, I did it again");
+ qb_log(LOG_INFO, "are you aware ...");
fd = fopen("/nothing.txt", "r+");
if (fd == NULL) {
@@ -51,17 +52,19 @@ static void func_one(void)
qb_leave();
}
-static void func_two(void)
+static void
+func_two(void)
{
qb_enter();
qb_logt(LOG_DEBUG, 0, "arf arf?");
- qb_logt(LOG_CRIT, MY_TAG_ONE, "arrrg!");
- qb_log(LOG_ERR, "oops, I did it again");
- qb_logt(LOG_INFO, MY_TAG_THREE, "are you aware ...");
+ qb_logt(LOG_CRIT, MY_TAG_ONE, "arrrg!");
+ qb_log(LOG_ERR, "oops, I did it again");
+ qb_logt(LOG_INFO, MY_TAG_THREE, "are you aware ...");
qb_leave();
}
-static void show_usage(const char *name)
+static void
+show_usage(const char *name)
{
printf("usage: \n");
printf("%s <options>\n", name);
@@ -80,9 +83,10 @@ static void show_usage(const char *name)
static int32_t do_blackbox = QB_FALSE;
static int32_t do_threaded = QB_FALSE;
-static void sigsegv_handler(int sig)
+static void
+sigsegv_handler(int sig)
{
- (void)signal (SIGSEGV, SIG_DFL);
+ (void)signal(SIGSEGV, SIG_DFL);
qb_log_fini();
if (do_blackbox) {
qb_log_blackbox_write_to_file("simple-log.fdata");
@@ -90,7 +94,8 @@ static void sigsegv_handler(int sig)
raise(SIGSEGV);
}
-static const char *my_tags_stringify(uint32_t tags)
+static const char *
+my_tags_stringify(uint32_t tags)
{
if (qb_bit_is_set(tags, QB_LOG_TAG_LIBQB_MSG_BIT)) {
return "libqb";
@@ -107,9 +112,7 @@ static const char *my_tags_stringify(uint32_t tags)
static void
trace_logger(int32_t t,
- struct qb_log_callsite *cs,
- time_t timestamp,
- const char *msg)
+ struct qb_log_callsite *cs, time_t timestamp, const char *msg)
{
char output_buffer[QB_LOG_MAX_LEN];
output_buffer[0] = '\0';
@@ -122,14 +125,15 @@ m_filter(struct qb_log_callsite *cs)
{
if ((cs->priority >= LOG_ALERT &&
cs->priority <= _log_priority) &&
- strcmp(cs->filename, __FILE__) == 0) {
+ strcmp(cs->filename, __FILE__) == 0) {
qb_bit_set(cs->targets, QB_LOG_STDERR);
} else {
qb_bit_clear(cs->targets, QB_LOG_STDERR);
}
}
-int32_t main(int32_t argc, char *argv[])
+int32_t
+main(int32_t argc, char *argv[])
{
const char *options = "vhteobdf:";
int32_t opt;
@@ -182,7 +186,6 @@ int32_t main(int32_t argc, char *argv[])
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_THREADED, do_threaded);
qb_log_tags_stringify_fn_set(my_tags_stringify);
-
if (do_stderr) {
qb_log_filter_fn_set(m_filter);
qb_log_format_set(QB_LOG_STDERR, "[%p] %4g: %f:%l %b");
@@ -244,4 +247,3 @@ int32_t main(int32_t argc, char *argv[])
qb_log_fini();
return 0;
}
-
diff --git a/examples/tcpclient.c b/examples/tcpclient.c
index e78f523..a795538 100644
--- a/examples/tcpclient.c
+++ b/examples/tcpclient.c
@@ -51,8 +51,9 @@ main(int argc, char *argv[])
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000);
- memcpy(&server_addr.sin_addr, host->h_addr_list[0],
sizeof(server_addr.sin_addr));
- bzero(&(server_addr.sin_zero),8);
+ memcpy(&server_addr.sin_addr, host->h_addr_list[0],
+ sizeof(server_addr.sin_addr));
+ bzero(&(server_addr.sin_zero), 8);
if (connect(sock, (struct sockaddr *)&server_addr,
sizeof(struct sockaddr)) == -1) {
@@ -60,7 +61,7 @@ main(int argc, char *argv[])
exit(1);
}
- while(1) {
+ while (1) {
printf("\nSEND (q or Q to quit) : ");
if (fgets(send_data, 1024, stdin) == NULL) {
continue;
diff --git a/examples/tcpserver.c b/examples/tcpserver.c
index 8d70fe1..41037cc 100644
--- a/examples/tcpserver.c
+++ b/examples/tcpserver.c
@@ -59,8 +59,7 @@ sock_read_fn(int32_t fd, int32_t revents, void *data)
}
recv_data[bytes_recieved] = '\0';
- if (strcmp(recv_data, "q") == 0 ||
- strcmp(recv_data, "Q") == 0) {
+ if (strcmp(recv_data, "q") == 0 || strcmp(recv_data, "Q") == 0) {
printf("Quiting connection from socket %d\n", fd);
close(fd);
return QB_FALSE;
@@ -76,7 +75,7 @@ static int32_t
sock_accept_fn(int32_t fd, int32_t revents, void *data)
{
struct sockaddr_in client_addr;
- qb_loop_t * ml = (qb_loop_t*)data;
+ qb_loop_t *ml = (qb_loop_t *) data;
socklen_t sin_size = sizeof(struct sockaddr_in);
int connected = accept(fd, (struct sockaddr *)&client_addr, &sin_size);
@@ -85,12 +84,9 @@ sock_accept_fn(int32_t fd, int32_t revents, void *data)
return QB_TRUE;
}
printf("I got a connection from (%s , %d)\n",
- inet_ntoa(client_addr.sin_addr),
- ntohs(client_addr.sin_port));
+ inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
- qb_loop_poll_add(ml, QB_LOOP_MED,
- connected, POLLIN,
- ml, sock_read_fn);
+ qb_loop_poll_add(ml, QB_LOOP_MED, connected, POLLIN, ml, sock_read_fn);
return QB_TRUE;
}
@@ -98,7 +94,7 @@ sock_accept_fn(int32_t fd, int32_t revents, void *data)
static int32_t
please_exit_fn(int32_t rsignal, void *data)
{
- qb_loop_t * ml = (qb_loop_t*)data;
+ qb_loop_t *ml = (qb_loop_t *) data;
printf("Shutting down at you request...\n");
qb_loop_stop(ml);
@@ -111,20 +107,16 @@ main(int argc, char *argv[])
int sock;
int true_opt = 1;
struct sockaddr_in server_addr;
- qb_loop_t * ml = qb_loop_create();
+ qb_loop_t *ml = qb_loop_create();
- if ((sock = socket(AF_INET,
- SOCK_STREAM,
- 0)) == -1) {
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("Socket");
exit(1);
}
if (setsockopt(sock,
SOL_SOCKET,
- SO_REUSEADDR,
- &true_opt,
- sizeof(int)) == -1) {
+ SO_REUSEADDR, &true_opt, sizeof(int)) == -1) {
perror("Setsockopt");
exit(1);
}
@@ -132,7 +124,7 @@ main(int argc, char *argv[])
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000);
server_addr.sin_addr.s_addr = INADDR_ANY;
- bzero(&(server_addr.sin_zero),8);
+ bzero(&(server_addr.sin_zero), 8);
printf("TCPServer binding to port 5000\n");
if (bind(sock,
@@ -149,14 +141,9 @@ main(int argc, char *argv[])
exit(1);
}
- qb_loop_poll_add(ml, QB_LOOP_MED,
- sock, POLLIN,
- ml, sock_accept_fn);
+ qb_loop_poll_add(ml, QB_LOOP_MED, sock, POLLIN, ml, sock_accept_fn);
- qb_loop_signal_add(ml, QB_LOOP_HIGH,
- SIGINT,
- ml, please_exit_fn,
- NULL);
+ qb_loop_signal_add(ml, QB_LOOP_HIGH, SIGINT, ml, please_exit_fn, NULL);
qb_loop_run(ml);
close(sock);
--
1.7.9.3