Skip to content

Commit

Permalink
Format sources with current clang-format configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Koviazin <[email protected]>
  • Loading branch information
mkmkme committed Aug 21, 2024
1 parent 8ea51b3 commit 3bbb07b
Show file tree
Hide file tree
Showing 77 changed files with 3,076 additions and 2,633 deletions.
28 changes: 15 additions & 13 deletions examples/async-ae.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#include <valkey/async.h>
#include <valkey/valkey.h>

#include <valkey/adapters/ae.h>

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include <valkey/valkey.h>
#include <valkey/async.h>
#include <valkey/adapters/ae.h>

/* Put event loop in the global scope, so it can be explicitly stopped */
static aeEventLoop *loop;

void getCallback(valkeyAsyncContext *c, void *r, void *privdata) {
valkeyReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
if (reply == NULL)
return;
printf("argv[%s]: %s\n", (char *)privdata, reply->str);

/* Disconnect after receiving the reply to GET */
valkeyAsyncDisconnect(c);
Expand All @@ -40,7 +42,7 @@ void disconnectCallback(const valkeyAsyncContext *c, int status) {
aeStop(loop);
}

int main (int argc, char **argv) {
int main(int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);

valkeyAsyncContext *c = valkeyAsyncConnect("127.0.0.1", 6379);
Expand All @@ -52,11 +54,11 @@ int main (int argc, char **argv) {

loop = aeCreateEventLoop(64);
valkeyAeAttach(loop, c);
valkeyAsyncSetConnectCallback(c,connectCallback);
valkeyAsyncSetDisconnectCallback(c,disconnectCallback);
valkeyAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
valkeyAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
valkeyAsyncSetConnectCallback(c, connectCallback);
valkeyAsyncSetDisconnectCallback(c, disconnectCallback);
valkeyAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc - 1],
strlen(argv[argc - 1]));
valkeyAsyncCommand(c, getCallback, (char *)"end-1", "GET key");
aeMain(loop);
return 0;
}

30 changes: 10 additions & 20 deletions examples/async-glib.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#include <stdlib.h>

#include <valkey/valkey.h>
#include <valkey/async.h>
#include <valkey/valkey.h>

#include <valkey/adapters/glib.h>

#include <stdlib.h>

static GMainLoop *mainloop;

static void
connect_cb (const valkeyAsyncContext *ac G_GNUC_UNUSED,
int status)
{
static void connect_cb(const valkeyAsyncContext *ac G_GNUC_UNUSED, int status) {
if (status != VALKEY_OK) {
g_printerr("Failed to connect: %s\n", ac->errstr);
g_main_loop_quit(mainloop);
Expand All @@ -18,10 +16,8 @@ connect_cb (const valkeyAsyncContext *ac G_GNUC_UNUSED,
}
}

static void
disconnect_cb (const valkeyAsyncContext *ac G_GNUC_UNUSED,
int status)
{
static void disconnect_cb(const valkeyAsyncContext *ac G_GNUC_UNUSED,
int status) {
if (status != VALKEY_OK) {
g_error("Failed to disconnect: %s", ac->errstr);
} else {
Expand All @@ -30,11 +26,8 @@ disconnect_cb (const valkeyAsyncContext *ac G_GNUC_UNUSED,
}
}

static void
command_cb(valkeyAsyncContext *ac,
gpointer r,
gpointer user_data G_GNUC_UNUSED)
{
static void command_cb(valkeyAsyncContext *ac, gpointer r,
gpointer user_data G_GNUC_UNUSED) {
valkeyReply *reply = r;

if (reply) {
Expand All @@ -44,10 +37,7 @@ command_cb(valkeyAsyncContext *ac,
valkeyAsyncDisconnect(ac);
}

gint
main (gint argc G_GNUC_UNUSED,
gchar *argv[] G_GNUC_UNUSED)
{
gint main(gint argc G_GNUC_UNUSED, gchar *argv[] G_GNUC_UNUSED) {
valkeyAsyncContext *ac;
GMainContext *context = NULL;
GSource *source;
Expand Down
27 changes: 15 additions & 12 deletions examples/async-ivykis.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include <valkey/async.h>
#include <valkey/valkey.h>

#include <valkey/adapters/ivykis.h>

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include <valkey/valkey.h>
#include <valkey/async.h>
#include <valkey/adapters/ivykis.h>

void getCallback(valkeyAsyncContext *c, void *r, void *privdata) {
valkeyReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
if (reply == NULL)
return;
printf("argv[%s]: %s\n", (char *)privdata, reply->str);

/* Disconnect after receiving the reply to GET */
valkeyAsyncDisconnect(c);
Expand All @@ -32,7 +34,7 @@ void disconnectCallback(const valkeyAsyncContext *c, int status) {
printf("Disconnected...\n");
}

int main (int argc, char **argv) {
int main(int argc, char **argv) {
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
#endif
Expand All @@ -47,10 +49,11 @@ int main (int argc, char **argv) {
}

valkeyIvykisAttach(c);
valkeyAsyncSetConnectCallback(c,connectCallback);
valkeyAsyncSetDisconnectCallback(c,disconnectCallback);
valkeyAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
valkeyAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
valkeyAsyncSetConnectCallback(c, connectCallback);
valkeyAsyncSetDisconnectCallback(c, disconnectCallback);
valkeyAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc - 1],
strlen(argv[argc - 1]));
valkeyAsyncCommand(c, getCallback, (char *)"end-1", "GET key");

iv_main();

Expand Down
27 changes: 15 additions & 12 deletions examples/async-libev.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include <valkey/async.h>
#include <valkey/valkey.h>

#include <valkey/adapters/libev.h>

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include <valkey/valkey.h>
#include <valkey/async.h>
#include <valkey/adapters/libev.h>

void getCallback(valkeyAsyncContext *c, void *r, void *privdata) {
valkeyReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
if (reply == NULL)
return;
printf("argv[%s]: %s\n", (char *)privdata, reply->str);

/* Disconnect after receiving the reply to GET */
valkeyAsyncDisconnect(c);
Expand All @@ -32,7 +34,7 @@ void disconnectCallback(const valkeyAsyncContext *c, int status) {
printf("Disconnected...\n");
}

int main (int argc, char **argv) {
int main(int argc, char **argv) {
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
#endif
Expand All @@ -45,10 +47,11 @@ int main (int argc, char **argv) {
}

valkeyLibevAttach(EV_DEFAULT_ c);
valkeyAsyncSetConnectCallback(c,connectCallback);
valkeyAsyncSetDisconnectCallback(c,disconnectCallback);
valkeyAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
valkeyAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
valkeyAsyncSetConnectCallback(c, connectCallback);
valkeyAsyncSetDisconnectCallback(c, disconnectCallback);
valkeyAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc - 1],
strlen(argv[argc - 1]));
valkeyAsyncCommand(c, getCallback, (char *)"end-1", "GET key");
ev_loop(EV_DEFAULT_ 0);
return 0;
}
35 changes: 18 additions & 17 deletions examples/async-libevent-ssl.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include <valkey/async.h>
#include <valkey/valkey.h>
#include <valkey/valkey_ssl.h>
#include <valkey/async.h>

#include <valkey/adapters/libevent.h>

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void getCallback(valkeyAsyncContext *c, void *r, void *privdata) {
valkeyReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
if (reply == NULL)
return;
printf("argv[%s]: %s\n", (char *)privdata, reply->str);

/* Disconnect after receiving the reply to GET */
valkeyAsyncDisconnect(c);
Expand All @@ -33,15 +35,15 @@ void disconnectCallback(const valkeyAsyncContext *c, int status) {
printf("Disconnected...\n");
}

int main (int argc, char **argv) {
int main(int argc, char **argv) {
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
#endif

struct event_base *base = event_base_new();
if (argc < 5) {
fprintf(stderr,
"Usage: %s <key> <host> <port> <cert> <certKey> [ca]\n", argv[0]);
fprintf(stderr, "Usage: %s <key> <host> <port> <cert> <certKey> [ca]\n",
argv[0]);
exit(1);
}

Expand All @@ -60,8 +62,7 @@ int main (int argc, char **argv) {

valkeyInitOpenSSL();

ssl = valkeyCreateSSLContext(caCert, NULL,
cert, certKey, NULL, &ssl_error);
ssl = valkeyCreateSSLContext(caCert, NULL, cert, certKey, NULL, &ssl_error);
if (!ssl) {
printf("Error: %s\n", valkeySSLContextGetError(ssl_error));
return 1;
Expand All @@ -78,11 +79,11 @@ int main (int argc, char **argv) {
exit(1);
}

valkeyLibeventAttach(c,base);
valkeyAsyncSetConnectCallback(c,connectCallback);
valkeyAsyncSetDisconnectCallback(c,disconnectCallback);
valkeyLibeventAttach(c, base);
valkeyAsyncSetConnectCallback(c, connectCallback);
valkeyAsyncSetDisconnectCallback(c, disconnectCallback);
valkeyAsyncCommand(c, NULL, NULL, "SET key %b", value, nvalue);
valkeyAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
valkeyAsyncCommand(c, getCallback, (char *)"end-1", "GET key");
event_base_dispatch(base);

valkeyFreeSSLContext(ssl);
Expand Down
27 changes: 14 additions & 13 deletions examples/async-libevent.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <valkey/async.h>
#include <valkey/valkey.h>

#include <valkey/adapters/libevent.h>

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include <valkey/valkey.h>
#include <valkey/async.h>
#include <valkey/adapters/libevent.h>

void getCallback(valkeyAsyncContext *c, void *r, void *privdata) {
valkeyReply *reply = r;
Expand All @@ -15,7 +16,7 @@ void getCallback(valkeyAsyncContext *c, void *r, void *privdata) {
}
return;
}
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
printf("argv[%s]: %s\n", (char *)privdata, reply->str);

/* Disconnect after receiving the reply to GET */
valkeyAsyncDisconnect(c);
Expand All @@ -37,7 +38,7 @@ void disconnectCallback(const valkeyAsyncContext *c, int status) {
printf("Disconnected...\n");
}

int main (int argc, char **argv) {
int main(int argc, char **argv) {
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
#endif
Expand All @@ -49,19 +50,19 @@ int main (int argc, char **argv) {
tv.tv_sec = 1;
options.connect_timeout = &tv;


valkeyAsyncContext *c = valkeyAsyncConnectWithOptions(&options);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);
return 1;
}

valkeyLibeventAttach(c,base);
valkeyAsyncSetConnectCallback(c,connectCallback);
valkeyAsyncSetDisconnectCallback(c,disconnectCallback);
valkeyAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
valkeyAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
valkeyLibeventAttach(c, base);
valkeyAsyncSetConnectCallback(c, connectCallback);
valkeyAsyncSetDisconnectCallback(c, disconnectCallback);
valkeyAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc - 1],
strlen(argv[argc - 1]));
valkeyAsyncCommand(c, getCallback, (char *)"end-1", "GET key");
event_base_dispatch(base);
return 0;
}
Loading

0 comments on commit 3bbb07b

Please sign in to comment.