From 3d9805e28c2486b01dce5049ae5f0feede01b7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Wed, 26 Jun 2024 07:24:05 +0200 Subject: [PATCH] Build all examples successfully with Make MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Svensson --- Makefile | 2 +- examples/Makefile | 24 ++++++++++++++++++--- examples/async-glib.c | 6 +++--- examples/async-libev.c | 6 +++--- examples/async-libevent-ssl.c | 8 +++---- examples/async-libevent.c | 6 +++--- examples/async-poll.c | 4 ++-- examples/blocking-push.c | 2 +- examples/blocking-ssl.c | 4 ++-- examples/blocking.c | 2 +- examples/cluster-async-tls.c | 7 +++--- examples/cluster-async.c | 18 ++++++++++------ examples/cluster-clientside-caching-async.c | 7 ++++-- examples/cluster-simple.c | 13 +++++------ examples/cluster-tls.c | 15 +++++++------ 15 files changed, 76 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 35fe1f90..712addbd 100644 --- a/Makefile +++ b/Makefile @@ -219,7 +219,7 @@ examples: $(STLIBNAME) clean: rm -rf $(OBJ_DIR) $(LIB_DIR) $(TEST_BINS) *.gcda *.gcno *.gcov - make -C examples clean + $(MAKE) -C examples clean INSTALL?= cp -pPR diff --git a/examples/Makefile b/examples/Makefile index 3521ff19..d8dc5baf 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,15 +1,18 @@ CC?=gcc CXX?=g++ -CFLAGS=-Wall -Wextra -g -O2 -I../include/valkey +CFLAGS=-Wall -Wextra -g -O2 -I../include STLIBNAME=../lib/libvalkey.a # Define examples EXAMPLES=example-blocking example-blocking-push example-async-libevent \ - example-async-libev example-async-glib example-async-poll + example-async-libev example-async-glib example-async-poll \ + example-cluster-async example-cluster-clientside-caching-async \ + example-cluster-simple ifeq ($(USE_SSL),1) - EXAMPLES+=blocking-ssl async-libevent-ssl + EXAMPLES+=example-blocking-ssl example-async-libevent-ssl \ + example-cluster-async-tls example-cluster-tls SSL_STLIBNAME=../lib/libvalkey_ssl.a SSL_LDFLAGS=-lssl -lcrypto endif @@ -92,5 +95,20 @@ example-async-qt: async-qt.cpp $(STLIBNAME) $(CXX) -o $@ $(CFLAGS) $(LDFLAGS) -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore -L$(QT_LIBRARY_DIR) qt-adapter-moc.o qt-example-moc.o $< -pthread $(STLIBNAME) -lQtCore endif +example-cluster-async: cluster-async.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -levent $(STLIBNAME) + +example-cluster-async-tls: cluster-async-tls.c $(STLIBNAME) $(SSL_STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -levent $(STLIBNAME) $(SSL_STLIBNAME) $(SSL_LDFLAGS) + +example-cluster-clientside-caching-async: cluster-clientside-caching-async.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -levent $(STLIBNAME) + +example-cluster-simple: cluster-simple.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< $(STLIBNAME) + +example-cluster-tls: cluster-tls.c $(STLIBNAME) $(SSL_STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< $(STLIBNAME) $(SSL_STLIBNAME) $(SSL_LDFLAGS) + clean: rm -f example-* *.o diff --git a/examples/async-glib.c b/examples/async-glib.c index 371a7330..5137edc5 100644 --- a/examples/async-glib.c +++ b/examples/async-glib.c @@ -1,8 +1,8 @@ #include -#include -#include -#include +#include +#include +#include static GMainLoop *mainloop; diff --git a/examples/async-libev.c b/examples/async-libev.c index 3d644b2d..dcb2a378 100644 --- a/examples/async-libev.c +++ b/examples/async-libev.c @@ -3,9 +3,9 @@ #include #include -#include -#include -#include +#include +#include +#include void getCallback(valkeyAsyncContext *c, void *r, void *privdata) { valkeyReply *reply = r; diff --git a/examples/async-libevent-ssl.c b/examples/async-libevent-ssl.c index dd1bf44c..31ec5912 100644 --- a/examples/async-libevent-ssl.c +++ b/examples/async-libevent-ssl.c @@ -3,10 +3,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include void getCallback(valkeyAsyncContext *c, void *r, void *privdata) { valkeyReply *reply = r; diff --git a/examples/async-libevent.c b/examples/async-libevent.c index 6ac91678..210443a8 100644 --- a/examples/async-libevent.c +++ b/examples/async-libevent.c @@ -3,9 +3,9 @@ #include #include -#include -#include -#include +#include +#include +#include void getCallback(valkeyAsyncContext *c, void *r, void *privdata) { valkeyReply *reply = r; diff --git a/examples/async-poll.c b/examples/async-poll.c index edc37205..b39eaf4c 100644 --- a/examples/async-poll.c +++ b/examples/async-poll.c @@ -4,8 +4,8 @@ #include #include -#include -#include +#include +#include /* Put in the global scope, so that loop can be explicitly stopped */ static int exit_loop = 0; diff --git a/examples/blocking-push.c b/examples/blocking-push.c index 03c0fe72..bf438d98 100644 --- a/examples/blocking-push.c +++ b/examples/blocking-push.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #define KEY_COUNT 5 diff --git a/examples/blocking-ssl.c b/examples/blocking-ssl.c index 47b5276c..990d27c2 100644 --- a/examples/blocking-ssl.c +++ b/examples/blocking-ssl.c @@ -2,8 +2,8 @@ #include #include -#include -#include +#include +#include #ifdef _MSC_VER #include /* For struct timeval */ diff --git a/examples/blocking.c b/examples/blocking.c index ddd9715e..ced05bb1 100644 --- a/examples/blocking.c +++ b/examples/blocking.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #ifdef _MSC_VER #include /* For struct timeval */ diff --git a/examples/cluster-async-tls.c b/examples/cluster-async-tls.c index f239e107..8d1c04f9 100644 --- a/examples/cluster-async-tls.c +++ b/examples/cluster-async-tls.c @@ -1,10 +1,9 @@ #include #include #include - -#include "adapters/libevent.h" -#include "valkeycluster.h" -#include "valkeycluster_ssl.h" +#include +#include +#include #define CLUSTER_NODE_TLS "127.0.0.1:7300" diff --git a/examples/cluster-async.c b/examples/cluster-async.c index 82cb220e..b703be1b 100644 --- a/examples/cluster-async.c +++ b/examples/cluster-async.c @@ -1,12 +1,12 @@ #include #include -#include -#include +#include +#include void getCallback(valkeyClusterAsyncContext *cc, void *r, void *privdata) { valkeyReply *reply = (valkeyReply *)r; if (reply == NULL) { - if (cc->errstr) { + if (cc->err) { printf("errstr: %s\n", cc->errstr); } return; @@ -20,7 +20,7 @@ void getCallback(valkeyClusterAsyncContext *cc, void *r, void *privdata) { void setCallback(valkeyClusterAsyncContext *cc, void *r, void *privdata) { valkeyReply *reply = (valkeyReply *)r; if (reply == NULL) { - if (cc->errstr) { + if (cc->err) { printf("errstr: %s\n", cc->errstr); } return; @@ -45,12 +45,18 @@ void disconnectCallback(const valkeyAsyncContext *ac, int status) { } int main(int argc, char **argv) { + (void) argc; + (void) argv; printf("Connecting...\n"); valkeyClusterAsyncContext *cc = valkeyClusterAsyncConnect("127.0.0.1:7000", VALKEYCLUSTER_FLAG_NULL); - if (cc && cc->err) { + if (!cc) { + printf("Error: Allocation failure\n"); + exit(-1); + } else if (cc->err) { printf("Error: %s\n", cc->errstr); - return 1; + // handle error + exit(-1); } struct event_base *base = event_base_new(); diff --git a/examples/cluster-clientside-caching-async.c b/examples/cluster-clientside-caching-async.c index cb109375..50b29632 100644 --- a/examples/cluster-clientside-caching-async.c +++ b/examples/cluster-clientside-caching-async.c @@ -4,8 +4,8 @@ * messages are received via the registered push callback. * The disconnect callback should also be used as an indication of invalidation. */ -#include -#include +#include +#include #include #include @@ -83,6 +83,7 @@ void getCallback1(valkeyClusterAsyncContext *acc, void *r, void *privdata) { /* Push message callback handling invalidation messages. */ void pushCallback(valkeyAsyncContext *ac, void *r) { + (void) ac; valkeyReply *reply = r; if (!(reply->type == VALKEY_REPLY_PUSH && reply->elements == 2 && reply->element[0]->type == VALKEY_REPLY_STRING && @@ -139,6 +140,8 @@ void modifyKey(const char *key, const char *value) { } int main(int argc, char **argv) { + (void) argc; + (void) argv; valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); diff --git a/examples/cluster-simple.c b/examples/cluster-simple.c index 518f8928..a14f458c 100644 --- a/examples/cluster-simple.c +++ b/examples/cluster-simple.c @@ -1,6 +1,6 @@ #include #include -#include +#include int main(int argc, char **argv) { UNUSED(argc); @@ -12,19 +12,20 @@ int main(int argc, char **argv) { valkeyClusterSetOptionConnectTimeout(cc, timeout); valkeyClusterSetOptionRouteUseSlots(cc); valkeyClusterConnect2(cc); - if (cc && cc->err) { + if (!cc) { + printf("Error: Allocation failure\n"); + exit(-1); + } else if (cc->err) { printf("Error: %s\n", cc->errstr); // handle error exit(-1); } - valkeyReply *reply = - (valkeyReply *)valkeyClusterCommand(cc, "SET %s %s", "key", "value"); + valkeyReply *reply = valkeyClusterCommand(cc, "SET %s %s", "key", "value"); printf("SET: %s\n", reply->str); freeReplyObject(reply); - valkeyReply *reply2 = - (valkeyReply *)valkeyClusterCommand(cc, "GET %s", "key"); + valkeyReply *reply2 = valkeyClusterCommand(cc, "GET %s", "key"); printf("GET: %s\n", reply2->str); freeReplyObject(reply2); diff --git a/examples/cluster-tls.c b/examples/cluster-tls.c index 820a42a2..8ce9a98b 100644 --- a/examples/cluster-tls.c +++ b/examples/cluster-tls.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include #define CLUSTER_NODE_TLS "127.0.0.1:7301" @@ -31,14 +31,16 @@ int main(int argc, char **argv) { valkeyClusterSetOptionParseSlaves(cc); valkeyClusterSetOptionEnableSSL(cc, ssl); valkeyClusterConnect2(cc); - if (cc && cc->err) { + if (!cc) { + printf("Error: Allocation failure\n"); + exit(-1); + } else if (cc->err) { printf("Error: %s\n", cc->errstr); // handle error exit(-1); } - valkeyReply *reply = - (valkeyReply *)valkeyClusterCommand(cc, "SET %s %s", "key", "value"); + valkeyReply *reply = valkeyClusterCommand(cc, "SET %s %s", "key", "value"); if (!reply) { printf("Reply missing: %s\n", cc->errstr); exit(-1); @@ -46,8 +48,7 @@ int main(int argc, char **argv) { printf("SET: %s\n", reply->str); freeReplyObject(reply); - valkeyReply *reply2 = - (valkeyReply *)valkeyClusterCommand(cc, "GET %s", "key"); + valkeyReply *reply2 = valkeyClusterCommand(cc, "GET %s", "key"); if (!reply2) { printf("Reply missing: %s\n", cc->errstr); exit(-1);