From a0fcb704c13b205824fdcd3003a8e4763070d9e3 Mon Sep 17 00:00:00 2001 From: michael-grunder Date: Sun, 23 Jun 2024 13:31:30 -0700 Subject: [PATCH] Rework build system to build unified library. * Update Makefile and CMakeLists.txt to build both standalone and cluster code. * Update dict API to make the API non-static for cluster usage. * Minor changes to a few examples and tests/test.c to get everything compiling. * Use CMake pkg-config .in files in the Makefile Fixes #22 --- .gitignore | 4 + CMakeLists.txt | 69 ++++++----- Makefile | 245 ++++++++++++++------------------------- examples/CMakeLists.txt | 34 +++--- examples/Makefile | 96 +++++++++++++++ examples/blocking-push.c | 2 +- include/valkey/dict.h | 20 ++-- src/async.c | 2 +- src/dict.c | 20 ++-- tests/test.c | 149 +++++------------------- 10 files changed, 301 insertions(+), 340 deletions(-) create mode 100644 .gitignore create mode 100644 examples/Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a621bb70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +obj +lib +compile_commands.json +.cache diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cbe2b55..a2c81c5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0) MACRO(getVersionBit name) SET(VERSION_REGEX "^#define ${name} (.+)$") - FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/valkey.h" + FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/valkey/valkey.h" VERSION_BIT REGEX ${VERSION_REGEX}) STRING(REGEX REPLACE ${VERSION_REGEX} "\\1" ${name} "${VERSION_BIT}") ENDMACRO(getVersionBit) @@ -32,13 +32,20 @@ SET(CMAKE_C_STANDARD 99) SET(CMAKE_DEBUG_POSTFIX d) SET(valkey_sources - alloc.c - async.c - valkey.c - net.c - read.c - sds.c - sockcompat.c) + src/adlist.c + src/alloc.c + src/async.c + src/command.c + src/crc16.c + src/dict.c + src/net.c + src/read.c + src/sds.c + src/sockcompat.c + src/valkey.c + src/valkeycluster.c + src/vkarray.c + src/vkutil.c) SET(valkey_sources ${valkey_sources}) @@ -66,7 +73,11 @@ ELSEIF(CMAKE_SYSTEM_NAME MATCHES "SunOS") TARGET_LINK_LIBRARIES(valkey PUBLIC socket) ENDIF() -TARGET_INCLUDE_DIRECTORIES(valkey PUBLIC $ $) +TARGET_INCLUDE_DIRECTORIES(valkey + PUBLIC + $ + $ +) CONFIGURE_FILE(valkey.pc.in valkey.pc @ONLY) @@ -158,10 +169,16 @@ IF(ENABLE_SSL) ENDIF() FIND_PACKAGE(OpenSSL REQUIRED) SET(valkey_ssl_sources - ssl.c) + src/ssl.c) ADD_LIBRARY(valkey_ssl ${valkey_ssl_sources}) ADD_LIBRARY(valkey::valkey_ssl ALIAS valkey_ssl) + TARGET_INCLUDE_DIRECTORIES(valkey_ssl + PRIVATE + $ + $ + ) + IF (APPLE AND BUILD_SHARED_LIBS) SET_PROPERTY(TARGET valkey_ssl PROPERTY LINK_FLAGS "-Wl,-undefined -Wl,dynamic_lookup") ENDIF() @@ -192,7 +209,7 @@ IF(ENABLE_SSL) CONFIGURATIONS Debug RelWithDebInfo) endif() - INSTALL(FILES valkey_ssl.h + INSTALL(FILES valkey_ssl.h valkeycluster_ssl.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/valkey) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/valkey_ssl.pc @@ -220,21 +237,21 @@ IF(ENABLE_SSL) DESTINATION ${CMAKE_CONF_INSTALL_DIR}) ENDIF() -IF(NOT DISABLE_TESTS) - ENABLE_TESTING() - ADD_EXECUTABLE(libvalkey-test test.c) - TARGET_LINK_LIBRARIES(libvalkey-test valkey) - IF(ENABLE_SSL_TESTS) - ADD_DEFINITIONS(-DVALKEY_TEST_SSL=1) - TARGET_LINK_LIBRARIES(libvalkey-test valkey_ssl) - ENDIF() - IF(ENABLE_ASYNC_TESTS) - ADD_DEFINITIONS(-DVALKEY_TEST_ASYNC=1) - TARGET_LINK_LIBRARIES(libvalkey-test event) - ENDIF() - ADD_TEST(NAME libvalkey-test - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh) -ENDIF() +#IF(NOT DISABLE_TESTS) +# ENABLE_TESTING() +# ADD_EXECUTABLE(libvalkey-test test.c) +# TARGET_LINK_LIBRARIES(libvalkey-test valkey) +# IF(ENABLE_SSL_TESTS) +# ADD_DEFINITIONS(-DVALKEY_TEST_SSL=1) +# TARGET_LINK_LIBRARIES(libvalkey-test valkey_ssl) +# ENDIF() +# IF(ENABLE_ASYNC_TESTS) +# ADD_DEFINITIONS(-DVALKEY_TEST_ASYNC=1) +# TARGET_LINK_LIBRARIES(libvalkey-test event) +# ENDIF() +# ADD_TEST(NAME libvalkey-test +# COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh) +#ENDIF() # Add examples IF(ENABLE_EXAMPLES) diff --git a/Makefile b/Makefile index af861c0f..4b44aa39 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,32 @@ # Copyright (C) 2010-2011 Pieter Noordhuis # This file is released under the BSD license, see the COPYING file -OBJ=alloc.o net.o valkey.o sds.o async.o read.o sockcompat.o -EXAMPLES=valkey-example valkey-example-libevent valkey-example-libev valkey-example-glib valkey-example-push valkey-example-poll -TESTS=libvalkey-test +SRC_DIR = src +OBJ_DIR = obj +LIB_DIR = lib +TEST_DIR = tests + +INCLUDE_DIR = include/valkey + +TEST_SRCS = $(wildcard $(TEST_DIR)/*.c) +TEST_OBJS = $(patsubst $(TEST_DIR)/%.c,$(OBJ_DIR)/%.o,$(TEST_SRCS)) +TEST_BINS = $(patsubst $(TEST_DIR)/%.c,$(TEST_DIR)/%,$(TEST_SRCS)) + +SOURCES = $(filter-out $(wildcard $(SRC_DIR)/*ssl*.c), $(wildcard $(SRC_DIR)/*.c)) +HEADERS = $(filter-out $(INCLUDE_DIR)/valkey_ssl.h, $(wildcard $(INCLUDE_DIR)/*.h)) + +OBJS = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SOURCES)) + LIBNAME=libvalkey -PKGCONFNAME=valkey.pc +PKGCONFNAME=$(LIB_DIR)/valkey.pc -LIBVALKEY_MAJOR=$(shell grep LIBVALKEY_MAJOR valkey.h | awk '{print $$3}') -LIBVALKEY_MINOR=$(shell grep LIBVALKEY_MINOR valkey.h | awk '{print $$3}') -LIBVALKEY_PATCH=$(shell grep LIBVALKEY_PATCH valkey.h | awk '{print $$3}') -LIBVALKEY_SONAME=$(shell grep LIBVALKEY_SONAME valkey.h | awk '{print $$3}') +PKGCONF_TEMPLATE = valkey.pc.in +SSL_PKGCONF_TEMPLATE = valkey_ssl.pc.in + +LIBVALKEY_MAJOR=$(shell grep LIBVALKEY_MAJOR $(INCLUDE_DIR)/valkey.h | awk '{print $$3}') +LIBVALKEY_MINOR=$(shell grep LIBVALKEY_MINOR $(INCLUDE_DIR)/valkey.h | awk '{print $$3}') +LIBVALKEY_PATCH=$(shell grep LIBVALKEY_PATCH $(INCLUDE_DIR)/valkey.h | awk '{print $$3}') +LIBVALKEY_SONAME=$(shell grep LIBVALKEY_SONAME include/valkey/valkey.h | awk '{print $$3}') # Installation related variables and target PREFIX?=/usr/local @@ -52,28 +68,33 @@ DYLIBSUFFIX=so STLIBSUFFIX=a DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(LIBVALKEY_SONAME) DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(LIBVALKEY_MAJOR) -DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX) +DYLIB_ROOT_NAME=$(LIBNAME).$(DYLIBSUFFIX) +DYLIBNAME=$(LIB_DIR)/$(DYLIB_ROOT_NAME) DYLIB_MAKE_CMD=$(CC) $(PLATFORM_FLAGS) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -STLIBNAME=$(LIBNAME).$(STLIBSUFFIX) +STLIB_ROOT_NAME=$(LIBNAME).$(STLIBSUFFIX) +STLIBNAME=$(LIB_DIR)/$(STLIB_ROOT_NAME) STLIB_MAKE_CMD=$(AR) rcs #################### SSL variables start #################### -SSL_OBJ=ssl.o SSL_LIBNAME=libvalkey_ssl -SSL_PKGCONFNAME=valkey_ssl.pc +SSL_PKGCONFNAME=$(LIB_DIR)/valkey_ssl.pc SSL_INSTALLNAME=install-ssl SSL_DYLIB_MINOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(LIBVALKEY_SONAME) SSL_DYLIB_MAJOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(LIBVALKEY_MAJOR) -SSL_DYLIBNAME=$(SSL_LIBNAME).$(DYLIBSUFFIX) -SSL_STLIBNAME=$(SSL_LIBNAME).$(STLIBSUFFIX) +SSL_ROOT_DYLIB_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX) +SSL_DYLIBNAME=$(LIB_DIR)/$(SSL_LIBNAME).$(DYLIBSUFFIX) +SSL_STLIBNAME=$(LIB_DIR)/$(SSL_LIBNAME).$(STLIBSUFFIX) SSL_DYLIB_MAKE_CMD=$(CC) $(PLATFORM_FLAGS) -shared -Wl,-soname,$(SSL_DYLIB_MINOR_NAME) USE_SSL?=0 + ifeq ($(USE_SSL),1) + SSL_SOURCES = $(wildcard $(SRC_DIR)/*ssl*.c) + SSL_OBJS = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SSL_SOURCES)) + # This is required for test.c only CFLAGS+=-DVALKEY_TEST_SSL - EXAMPLES+=valkey-example-ssl valkey-example-libevent-ssl SSL_STLIB=$(SSL_STLIBNAME) SSL_DYLIB=$(SSL_DYLIBNAME) SSL_PKGCONF=$(SSL_PKGCONFNAME) @@ -86,7 +107,6 @@ else endif ##################### SSL variables end ##################### - # Platform-specific overrides uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') @@ -146,108 +166,42 @@ ifeq ($(uname_S),Darwin) DYLIB_PLUGIN=-Wl,-undefined -Wl,dynamic_lookup endif -all: dynamic static libvalkey-test pkgconfig - -dynamic: $(DYLIBNAME) $(SSL_DYLIB) - -static: $(STLIBNAME) $(SSL_STLIB) - -pkgconfig: $(PKGCONFNAME) $(SSL_PKGCONF) - -# Deps (use make dep to generate this) -alloc.o: alloc.c fmacros.h alloc.h -async.o: async.c fmacros.h alloc.h async.h valkey.h read.h sds.h net.h dict.c dict.h win32.h async_private.h -dict.o: dict.c fmacros.h alloc.h dict.h -valkey.o: valkey.c fmacros.h valkey.h read.h sds.h alloc.h net.h async.h win32.h -net.o: net.c fmacros.h net.h valkey.h read.h sds.h alloc.h sockcompat.h win32.h -read.o: read.c fmacros.h alloc.h read.h sds.h win32.h -sds.o: sds.c sds.h sdsalloc.h alloc.h -sockcompat.o: sockcompat.c sockcompat.h -test.o: test.c fmacros.h valkey.h read.h sds.h alloc.h net.h sockcompat.h win32.h - -$(DYLIBNAME): $(OBJ) - $(DYLIB_MAKE_CMD) -o $(DYLIBNAME) $(OBJ) $(REAL_LDFLAGS) - -$(STLIBNAME): $(OBJ) - $(STLIB_MAKE_CMD) $(STLIBNAME) $(OBJ) - -#################### SSL building rules start #################### -$(SSL_DYLIBNAME): $(SSL_OBJ) - $(SSL_DYLIB_MAKE_CMD) $(DYLIB_PLUGIN) -o $(SSL_DYLIBNAME) $(SSL_OBJ) $(REAL_LDFLAGS) $(LDFLAGS) $(SSL_LDFLAGS) +all: dynamic static pkgconfig -$(SSL_STLIBNAME): $(SSL_OBJ) - $(STLIB_MAKE_CMD) $(SSL_STLIBNAME) $(SSL_OBJ) +$(DYLIBNAME): $(OBJS) | $(LIB_DIR) + $(DYLIB_MAKE_CMD) -o $(DYLIBNAME) $(OBJS) $(REAL_LDFLAGS) -$(SSL_OBJ): ssl.c valkey.h read.h sds.h alloc.h async.h win32.h async_private.h -#################### SSL building rules end #################### +$(STLIBNAME): $(OBJS) | $(LIB_DIR) + $(STLIB_MAKE_CMD) $(STLIBNAME) $(OBJS) -# Binaries: -valkey-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -levent $(STLIBNAME) $(REAL_LDFLAGS) +$(SSL_DYLIBNAME): $(SSL_OBJS) + $(SSL_DYLIB_MAKE_CMD) $(DYLIB_PLUGIN) -o $(SSL_DYLIBNAME) $(SSL_OBJS) $(REAL_LDFLAGS) $(LDFLAGS) $(SSL_LDFLAGS) -valkey-example-libevent-ssl: examples/example-libevent-ssl.c adapters/libevent.h $(STLIBNAME) $(SSL_STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -levent $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS) +$(SSL_STLIBNAME): $(SSL_OBJS) + $(STLIB_MAKE_CMD) $(SSL_STLIBNAME) $(SSL_OBJS) -valkey-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -lev $(STLIBNAME) $(REAL_LDFLAGS) +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) + $(CC) -std=c99 $(REAL_CFLAGS) -I$(INCLUDE_DIR) -MMD -MP -c $< -o $@ -valkey-example-libhv: examples/example-libhv.c adapters/libhv.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -lhv $(STLIBNAME) $(REAL_LDFLAGS) +$(OBJ_DIR)/%.o: $(TEST_DIR)/%.c | $(OBJ_DIR) + $(CC) -std=c99 $(REAL_CFLAGS) -I$(INCLUDE_DIR) -MMD -MP -c $< -o $@ -valkey-example-glib: examples/example-glib.c adapters/glib.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(shell pkg-config --cflags --libs glib-2.0) $(STLIBNAME) $(REAL_LDFLAGS) +$(TEST_DIR)/%: $(OBJ_DIR)/%.o $(STLIBNAME) + $(CC) -o $@ $< $(STLIBNAME) $(LDFLAGS) $(SSL_LDLAGS) $(TEST_LDFLAGS) -valkey-example-ivykis: examples/example-ivykis.c adapters/ivykis.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -livykis $(STLIBNAME) $(REAL_LDFLAGS) +$(OBJ_DIR): + mkdir -p $(OBJ_DIR) -valkey-example-macosx: examples/example-macosx.c adapters/macosx.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -framework CoreFoundation $(STLIBNAME) $(REAL_LDFLAGS) +$(LIB_DIR): + mkdir -p $(LIB_DIR) -valkey-example-ssl: examples/example-ssl.c $(STLIBNAME) $(SSL_STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS) - -valkey-example-poll: examples/example-poll.c adapters/poll.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(REAL_LDFLAGS) - -ifndef AE_DIR -valkey-example-ae: - @echo "Please specify AE_DIR (e.g. /src)" - @false -else -valkey-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(AE_DIR) $< $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o $(AE_DIR)/../deps/jemalloc/lib/libjemalloc.a -pthread $(STLIBNAME) -endif - -ifndef LIBUV_DIR -# dynamic link libuv.so -valkey-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. -I$(LIBUV_DIR)/include $< -luv -lpthread -lrt $(STLIBNAME) $(REAL_LDFLAGS) -else -# use user provided static lib -valkey-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME) $(REAL_LDFLAGS) -endif - -ifeq ($(and $(QT_MOC),$(QT_INCLUDE_DIR),$(QT_LIBRARY_DIR)),) -valkey-example-qt: - @echo "Please specify QT_MOC, QT_INCLUDE_DIR AND QT_LIBRARY_DIR" - @false -else -valkey-example-qt: examples/example-qt.cpp adapters/qt.h $(STLIBNAME) - $(QT_MOC) adapters/qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \ - $(CXX) -x c++ -o qt-adapter-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore - $(QT_MOC) examples/example-qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \ - $(CXX) -x c++ -o qt-example-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore - $(CXX) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -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 +dynamic: $(DYLIBNAME) $(SSL_DYLIB) -valkey-example: examples/example.c $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(REAL_LDFLAGS) +static: $(STLIBNAME) $(SSL_STLIB) -valkey-example-push: examples/example-push.c $(STLIBNAME) - $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(REAL_LDFLAGS) +pkgconfig: $(PKGCONFNAME) $(SSL_PKGCONF) -examples: $(EXAMPLES) +-include $(OBJS:.o=.d) TEST_LIBS = $(STLIBNAME) $(SSL_STLIB) TEST_LDFLAGS = $(SSL_LDFLAGS) @@ -258,73 +212,50 @@ ifeq ($(TEST_ASYNC),1) TEST_LDFLAGS += -levent endif -libvalkey-test: test.o $(TEST_LIBS) - $(CC) -o $@ $(REAL_CFLAGS) -I. $^ $(REAL_LDFLAGS) $(TEST_LDFLAGS) - -valkey-%: %.o $(STLIBNAME) - $(CC) $(REAL_CFLAGS) -o $@ $< $(TEST_LIBS) $(REAL_LDFLAGS) +tests: $(TEST_BINS) -test: libvalkey-test - ./libvalkey-test - -check: libvalkey-test - TEST_SSL=$(USE_SSL) ./test.sh - -.c.o: - $(CC) -std=c99 -c $(REAL_CFLAGS) $< +examples: $(STLIBNAME) + $(MAKE) -C examples clean: - rm -rf $(DYLIBNAME) $(STLIBNAME) $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/valkey-example* *.o *.gcda *.gcno *.gcov - -dep: - $(CC) $(CPPFLAGS) $(CFLAGS) -MM *.c + rm -rf $(OBJ_DIR) $(LIB_DIR) $(TEST_BINS) *.gcda *.gcno *.gcov + rm -rf examples/example-* INSTALL?= cp -pPR -$(PKGCONFNAME): valkey.h +$(PKGCONFNAME): $(PKGCONF_TEMPLATE) @echo "Generating $@ for pkgconfig..." - @echo prefix=$(PREFIX) > $@ - @echo exec_prefix=\$${prefix} >> $@ - @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@ - @echo includedir=$(PREFIX)/include >> $@ - @echo pkgincludedir=$(PREFIX)/$(INCLUDE_PATH) >> $@ - @echo >> $@ - @echo Name: valkey >> $@ - @echo Description: C client library for Valkey. >> $@ - @echo Version: $(LIBVALKEY_MAJOR).$(LIBVALKEY_MINOR).$(LIBVALKEY_PATCH) >> $@ - @echo Libs: -L\$${libdir} -lvalkey >> $@ - @echo Cflags: -I\$${pkgincludedir} -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@ - -$(SSL_PKGCONFNAME): valkey_ssl.h + sed \ + -e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|g' \ + -e 's|@CMAKE_INSTALL_LIBDIR@|$(INSTALL_LIBRARY_PATH)|g' \ + -e 's|@PROJECT_VERSION@|$(LIBVALKEY_SONAME)|g' \ + $< > $@ + +$(SSL_PKGCONFNAME): $(SSL_PKGCONF_TEMPLATE) @echo "Generating $@ for pkgconfig..." - @echo prefix=$(PREFIX) > $@ - @echo exec_prefix=\$${prefix} >> $@ - @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@ - @echo includedir=$(PREFIX)/include >> $@ - @echo pkgincludedir=$(PREFIX)/$(INCLUDE_PATH) >> $@ - @echo >> $@ - @echo Name: valkey_ssl >> $@ - @echo Description: SSL Support for valkey. >> $@ - @echo Version: $(LIBVALKEY_MAJOR).$(LIBVALKEY_MINOR).$(LIBVALKEY_PATCH) >> $@ - @echo Requires: valkey >> $@ - @echo Libs: -L\$${libdir} -lvalkey_ssl >> $@ - @echo Libs.private: -lssl -lcrypto >> $@ + sed \ + -e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|g' \ + -e 's|@CMAKE_INSTALL_LIBDIR@|$(INSTALL_LIBRARY_PATH)|g' \ + -e 's|@PROJECT_VERSION@|$(LIBVALKEY_SONAME)|g' \ + $< > $@ install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME) $(SSL_INSTALL) - mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL_LIBRARY_PATH) - $(INSTALL) valkey.h async.h read.h sds.h alloc.h sockcompat.h $(INSTALL_INCLUDE_PATH) - $(INSTALL) adapters/*.h $(INSTALL_INCLUDE_PATH)/adapters + mkdir -p $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL_LIBRARY_PATH) + $(INSTALL) $(HEADERS) $(INSTALL_INCLUDE_PATH) + $(INSTALL) $(INCLUDE_DIR)/adapters/*.h $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME) - cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIBNAME) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIB_MAJOR_NAME) + ln -sf $(DYLIB_MINOR_NAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_ROOT_NAME) + ln -sf $(DYLIB_MINOR_NAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MAJOR_NAME) $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH) mkdir -p $(INSTALL_PKGCONF_PATH) $(INSTALL) $(PKGCONFNAME) $(INSTALL_PKGCONF_PATH) install-ssl: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME) mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH) - $(INSTALL) valkey_ssl.h $(INSTALL_INCLUDE_PATH) + $(INSTALL) $(INCLUDE_DIR)/valkey_ssl.h $(INSTALL_INCLUDE_PATH) $(INSTALL) $(SSL_DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(SSL_DYLIB_MINOR_NAME) - cd $(INSTALL_LIBRARY_PATH) && ln -sf $(SSL_DYLIB_MINOR_NAME) $(SSL_DYLIBNAME) && ln -sf $(SSL_DYLIB_MINOR_NAME) $(SSL_DYLIB_MAJOR_NAME) + ln -sf $(SSL_DYLIB_MINOR_NAME) $(INSTALL_LIBRARY_PATH)/$(SSL_ROOT_DYLIB_NAME) + ln -sf $(SSL_DYLIB_MINOR_NAME) $(INSTALL_LIBRARY_PATH)/$(SSL_DYLIB_MAJOR_NAME) $(INSTALL) $(SSL_STLIBNAME) $(INSTALL_LIBRARY_PATH) mkdir -p $(INSTALL_PKGCONF_PATH) $(INSTALL) $(SSL_PKGCONFNAME) $(INSTALL_PKGCONF_PATH) @@ -352,7 +283,7 @@ coverage: gcov lcov -q -l tmp/lcov/valkey.info genhtml --legend -q -o tmp/lcov/report tmp/lcov/valkey.info -noopt: - $(MAKE) OPTIMIZATION="" +debug: + $(MAKE) OPTIMIZATION="-O0" -.PHONY: all test check clean dep install 32bit 32bit-vars gprof gcov noopt +.PHONY: all test check clean install 32bit 32bit-vars gprof gcov noopt diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 49901ece..35db2ca3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,8 +5,8 @@ PKG_CHECK_MODULES(GLIB2 glib-2.0) if (GLIB2_FOUND) INCLUDE_DIRECTORIES(${GLIB2_INCLUDE_DIRS}) LINK_DIRECTORIES(${GLIB2_LIBRARY_DIRS}) - ADD_EXECUTABLE(example-glib example-glib.c) - TARGET_LINK_LIBRARIES(example-glib valkey ${GLIB2_LIBRARIES}) + ADD_EXECUTABLE(async-glib async-glib.c) + TARGET_LINK_LIBRARIES(async-glib valkey ${GLIB2_LIBRARIES}) ENDIF(GLIB2_FOUND) FIND_PATH(LIBEV ev.h @@ -15,38 +15,38 @@ FIND_PATH(LIBEV ev.h if (LIBEV) # Just compile and link with libev - ADD_EXECUTABLE(example-libev example-libev.c) - TARGET_LINK_LIBRARIES(example-libev valkey ev) + ADD_EXECUTABLE(async-libev async-libev.c) + TARGET_LINK_LIBRARIES(async-libev valkey ev) ENDIF() FIND_PATH(LIBEVENT event.h) if (LIBEVENT) - ADD_EXECUTABLE(example-libevent example-libevent.c) - TARGET_LINK_LIBRARIES(example-libevent valkey event) + ADD_EXECUTABLE(async-libevent async-libevent.c) + TARGET_LINK_LIBRARIES(async-libevent valkey event) ENDIF() FIND_PATH(LIBHV hv/hv.h) IF (LIBHV) - ADD_EXECUTABLE(example-libhv example-libhv.c) - TARGET_LINK_LIBRARIES(example-libhv valkey hv) + ADD_EXECUTABLE(async-libhv async-libhv.c) + TARGET_LINK_LIBRARIES(async-libhv valkey hv) ENDIF() FIND_PATH(LIBUV uv.h) IF (LIBUV) - ADD_EXECUTABLE(example-libuv example-libuv.c) - TARGET_LINK_LIBRARIES(example-libuv valkey uv) + ADD_EXECUTABLE(async-libuv async-libuv.c) + TARGET_LINK_LIBRARIES(async-libuv valkey uv) ENDIF() FIND_PATH(LIBSDEVENT systemd/sd-event.h) IF (LIBSDEVENT) - ADD_EXECUTABLE(example-libsdevent example-libsdevent.c) - TARGET_LINK_LIBRARIES(example-libsdevent valkey systemd) + ADD_EXECUTABLE(async-libsdevent async-libsdevent.c) + TARGET_LINK_LIBRARIES(async-libsdevent valkey systemd) ENDIF() IF (APPLE) FIND_LIBRARY(CF CoreFoundation) - ADD_EXECUTABLE(example-macosx example-macosx.c) - TARGET_LINK_LIBRARIES(example-macosx valkey ${CF}) + ADD_EXECUTABLE(async-macosx async-macosx.c) + TARGET_LINK_LIBRARIES(async-macosx valkey ${CF}) ENDIF() IF (ENABLE_SSL) @@ -54,8 +54,8 @@ IF (ENABLE_SSL) TARGET_LINK_LIBRARIES(example-ssl valkey valkey_ssl) ENDIF() -ADD_EXECUTABLE(example example.c) +ADD_EXECUTABLE(example blocking.c) TARGET_LINK_LIBRARIES(example valkey) -ADD_EXECUTABLE(example-push example-push.c) -TARGET_LINK_LIBRARIES(example-push valkey) +ADD_EXECUTABLE(blocking-push blocking-push.c) +TARGET_LINK_LIBRARIES(blocking-push valkey) diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 00000000..3521ff19 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,96 @@ +CC?=gcc +CXX?=g++ + +CFLAGS=-Wall -Wextra -g -O2 -I../include/valkey +STLIBNAME=../lib/libvalkey.a + +# Define examples +EXAMPLES=example-blocking example-blocking-push example-async-libevent \ + example-async-libev example-async-glib example-async-poll + +ifeq ($(USE_SSL),1) + EXAMPLES+=blocking-ssl async-libevent-ssl + SSL_STLIBNAME=../lib/libvalkey_ssl.a + SSL_LDFLAGS=-lssl -lcrypto +endif + +.PHONY: all clean + +all: $(EXAMPLES) + +$(STLIBNAME): + $(MAKE) -C ../ + +$(SSL_STLIBNAME): + USE_SSL=1 $(MAKE) -C ../ + +example-blocking: blocking.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< $(STLIBNAME) + +example-blocking-push: blocking-push.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< $(STLIBNAME) + +example-blocking-ssl: blocking-ssl.c $(STLIBNAME) $(SSL_STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< $(STLIBNAME) $(SSL_STLIBNAME) $(SSL_LDFLAGS) + +example-async-libevent: async-libevent.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -levent $(STLIBNAME) + +example-async-libevent-ssl: async-libevent-ssl.c $(STLIBNAME) $(SSL_STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -levent $(STLIBNAME) $(SSL_STLIBNAME) $(SSL_LDFLAGS) + +example-async-libev: async-libev.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -lev $(STLIBNAME) + +example-async-libhv: async-libhv.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -lhv $(STLIBNAME) + +example-async-libsdevent: async-libsdevent.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -lsdevent $(STLIBNAME) + +example-async-glib: async-glib.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< $(shell pkg-config --cflags --libs glib-2.0) $(STLIBNAME) + +example-async-ivykis: async-ivykis.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -livykis $(STLIBNAME) + +example-async-macosx: async-macosx.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< -framework CoreFoundation $(STLIBNAME) + +example-async-poll: async-poll.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $< $(STLIBNAME) + +ifndef AE_DIR +example-async-ae: + @echo "Please specify AE_DIR (e.g. /src)" + @false +else +example-async-ae: async-ae.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) -I$(AE_DIR) $< $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o $(AE_DIR)/../deps/jemalloc/lib/libjemalloc.a -pthread $(STLIBNAME) +endif + +ifndef LIBUV_DIR +# dynamic link libuv.so +example-async-libuv: async-libuv.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) -I$(LIBUV_DIR)/include $< -luv -lpthread -lrt $(STLIBNAME) +else +# use user provided static lib +example-async-libuv: async-libuv.c $(STLIBNAME) + $(CC) -o $@ $(CFLAGS) -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME) +endif + +ifeq ($(and $(QT_MOC),$(QT_INCLUDE_DIR),$(QT_LIBRARY_DIR)),) +example-async-qt: + @echo "Please specify QT_MOC, QT_INCLUDE_DIR AND QT_LIBRARY_DIR" + @false +else +example-async-qt: async-qt.cpp $(STLIBNAME) + $(QT_MOC) .adapters/qt.h -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \ + $(CXX) -x c++ -o qt-adapter-moc.o -c - $(CFLAGS) -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore + $(QT_MOC) async-qt.h -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \ + $(CXX) -x c++ -o qt-example-moc.o -c - $(CFLAGS) -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore + $(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 + +clean: + rm -f example-* *.o diff --git a/examples/blocking-push.c b/examples/blocking-push.c index 3ecceb65..03c0fe72 100644 --- a/examples/blocking-push.c +++ b/examples/blocking-push.c @@ -63,7 +63,7 @@ static void enableClientTracking(valkeyContext *c) { if (reply->type != VALKEY_REPLY_MAP) { fprintf(stderr, "Error: Can't send HELLO 3 command. Are you sure you're "); - fprintf(stderr, "connected to valkey-server >= 6.0.0?\Server error: %s\n", + fprintf(stderr, "connected to valkey-server >= 6.0.0?\nServer error: %s\n", reply->type == VALKEY_REPLY_ERROR ? reply->str : "(unknown)"); exit(-1); } diff --git a/include/valkey/dict.h b/include/valkey/dict.h index 6ad0acd8..d059f6b3 100644 --- a/include/valkey/dict.h +++ b/include/valkey/dict.h @@ -111,15 +111,15 @@ typedef struct dictIterator { #define dictSize(ht) ((ht)->used) /* API */ -static unsigned int dictGenHashFunction(const unsigned char *buf, int len); -static dict *dictCreate(dictType *type, void *privDataPtr); -static int dictExpand(dict *ht, unsigned long size); -static int dictAdd(dict *ht, void *key, void *val); -static int dictReplace(dict *ht, void *key, void *val); -static int dictDelete(dict *ht, const void *key); -static void dictRelease(dict *ht); -static dictEntry * dictFind(dict *ht, const void *key); -static void dictInitIterator(dictIterator *iter, dict *ht); -static dictEntry *dictNext(dictIterator *iter); +unsigned int dictGenHashFunction(const unsigned char *buf, int len); +dict *dictCreate(dictType *type, void *privDataPtr); +int dictExpand(dict *ht, unsigned long size); +int dictAdd(dict *ht, void *key, void *val); +int dictReplace(dict *ht, void *key, void *val); +int dictDelete(dict *ht, const void *key); +void dictRelease(dict *ht); +dictEntry * dictFind(dict *ht, const void *key); +void dictInitIterator(dictIterator *iter, dict *ht); +dictEntry *dictNext(dictIterator *iter); #endif /* __DICT_H */ diff --git a/src/async.c b/src/async.c index a18ce8a6..9dd398d1 100644 --- a/src/async.c +++ b/src/async.c @@ -41,7 +41,7 @@ #include #include "async.h" #include "net.h" -#include "dict.c" +#include "dict.h" #include "sds.h" #include "win32.h" diff --git a/src/dict.c b/src/dict.c index 2ba4cf78..9a365a80 100644 --- a/src/dict.c +++ b/src/dict.c @@ -51,7 +51,7 @@ static int _dictInit(dict *ht, dictType *type, void *privDataPtr); /* Generic hash function (a popular one from Bernstein). * I tested a few and this was the best. */ -static unsigned int dictGenHashFunction(const unsigned char *buf, int len) { +unsigned int dictGenHashFunction(const unsigned char *buf, int len) { unsigned int hash = 5381; while (len--) @@ -71,7 +71,7 @@ static void _dictReset(dict *ht) { } /* Create a new hash table */ -static dict *dictCreate(dictType *type, void *privDataPtr) { +dict *dictCreate(dictType *type, void *privDataPtr) { dict *ht = vk_malloc(sizeof(*ht)); if (ht == NULL) return NULL; @@ -89,7 +89,7 @@ static int _dictInit(dict *ht, dictType *type, void *privDataPtr) { } /* Expand or create the hashtable */ -static int dictExpand(dict *ht, unsigned long size) { +int dictExpand(dict *ht, unsigned long size) { dict n; /* the new hashtable */ unsigned long realsize = _dictNextPower(size), i; @@ -138,7 +138,7 @@ static int dictExpand(dict *ht, unsigned long size) { } /* Add an element to the target hash table */ -static int dictAdd(dict *ht, void *key, void *val) { +int dictAdd(dict *ht, void *key, void *val) { int index; dictEntry *entry; @@ -166,7 +166,7 @@ static int dictAdd(dict *ht, void *key, void *val) { * Return 1 if the key was added from scratch, 0 if there was already an * element with such key and dictReplace() just performed a value update * operation. */ -static int dictReplace(dict *ht, void *key, void *val) { +int dictReplace(dict *ht, void *key, void *val) { dictEntry *entry, auxentry; /* Try to add the element. If the key @@ -191,7 +191,7 @@ static int dictReplace(dict *ht, void *key, void *val) { } /* Search and remove an element */ -static int dictDelete(dict *ht, const void *key) { +int dictDelete(dict *ht, const void *key) { unsigned int h; dictEntry *de, *prevde; @@ -247,12 +247,12 @@ static int _dictClear(dict *ht) { } /* Clear & Release the hash table */ -static void dictRelease(dict *ht) { +void dictRelease(dict *ht) { _dictClear(ht); vk_free(ht); } -static dictEntry *dictFind(dict *ht, const void *key) { +dictEntry *dictFind(dict *ht, const void *key) { dictEntry *he; unsigned int h; @@ -267,14 +267,14 @@ static dictEntry *dictFind(dict *ht, const void *key) { return NULL; } -static void dictInitIterator(dictIterator *iter, dict *ht) { +void dictInitIterator(dictIterator *iter, dict *ht) { iter->ht = ht; iter->index = -1; iter->entry = NULL; iter->nextEntry = NULL; } -static dictEntry *dictNext(dictIterator *iter) { +dictEntry *dictNext(dictIterator *iter) { while (1) { if (iter->entry == NULL) { iter->index++; diff --git a/tests/test.c b/tests/test.c index 2844f72a..b3d43c0f 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1,10 +1,11 @@ -#include "fmacros.h" +#define _POSIX_C_SOURCE 200112L #include "sockcompat.h" #include #include #include #ifndef _WIN32 #include +#include #include #endif #include @@ -12,6 +13,7 @@ #include #include #include +#include #include "valkey.h" #include "async.h" @@ -23,8 +25,6 @@ #include "adapters/libevent.h" #include #endif -#include "net.h" -#include "win32.h" enum connection_type { CONN_TCP, @@ -76,12 +76,12 @@ static int tests = 0, fails = 0, skips = 0; #define test_cond(_c) if(_c) printf("\033[0;32mPASSED\033[0;0m\n"); else {printf("\033[0;31mFAILED\033[0;0m\n"); fails++;} #define test_skipped() { printf("\033[01;33mSKIPPED\033[0;0m\n"); skips++; } -static void millisleep(int ms) -{ +static void millisleep(int ms) { #ifdef _MSC_VER Sleep(ms); #else - usleep(ms*1000); + struct timespec ts = { ms / 1000, (ms % 1000) * 1000000 }; + clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); #endif } @@ -876,6 +876,18 @@ static void test_free_null(void) { test_cond(reply == NULL); } +/* Wrap malloc to abort on failure so OOM checks don't make the test logic + * harder to follow. */ +static void *vk_malloc_safe(size_t size) { + void *ptr = vk_malloc(size); + if (ptr == NULL) { + fprintf(stderr, "Error: Out of memory\n"); + exit(-1); + } + + return ptr; +} + static void *vk_malloc_fail(size_t size) { (void)size; return NULL; @@ -900,6 +912,18 @@ static void *vk_realloc_fail(void *ptr, size_t size) { return NULL; } +static char *vk_test_strdup(const char *s) { + size_t len; + char *dup; + + len = strlen(s); + dup = vk_malloc_safe(len + 1); + + memcpy(dup,s,len + 1); + + return dup; +} + static void test_allocator_injection(void) { void *ptr; @@ -907,7 +931,7 @@ static void test_allocator_injection(void) { .mallocFn = vk_malloc_fail, .callocFn = vk_calloc_fail, .reallocFn = vk_realloc_fail, - .strdupFn = strdup, + .strdupFn = vk_test_strdup, .freeFn = free, }; @@ -1420,18 +1444,6 @@ static void test_invalid_timeout_errors(struct config config) { valkeyFree(c); } -/* Wrap malloc to abort on failure so OOM checks don't make the test logic - * harder to follow. */ -void *vk_malloc_safe(size_t size) { - void *ptr = vk_malloc(size); - if (ptr == NULL) { - fprintf(stderr, "Error: Out of memory\n"); - exit(-1); - } - - return ptr; -} - static void test_throughput(struct config config) { valkeyContext *c = do_connect(config); valkeyReply **replies; @@ -1521,105 +1533,6 @@ static void test_throughput(struct config config) { disconnect(c, 0); } -// static long __test_callback_flags = 0; -// static void __test_callback(valkeyContext *c, void *privdata) { -// ((void)c); -// /* Shift to detect execution order */ -// __test_callback_flags <<= 8; -// __test_callback_flags |= (long)privdata; -// } -// -// static void __test_reply_callback(valkeyContext *c, valkeyReply *reply, void *privdata) { -// ((void)c); -// /* Shift to detect execution order */ -// __test_callback_flags <<= 8; -// __test_callback_flags |= (long)privdata; -// if (reply) freeReplyObject(reply); -// } -// -// static valkeyContext *__connect_nonblock() { -// /* Reset callback flags */ -// __test_callback_flags = 0; -// return valkeyConnectNonBlock("127.0.0.1", port, NULL); -// } -// -// static void test_nonblocking_connection() { -// valkeyContext *c; -// int wdone = 0; -// -// test("Calls command callback when command is issued: "); -// c = __connect_nonblock(); -// valkeySetCommandCallback(c,__test_callback,(void*)1); -// valkeyCommand(c,"PING"); -// test_cond(__test_callback_flags == 1); -// valkeyFree(c); -// -// test("Calls disconnect callback on valkeyDisconnect: "); -// c = __connect_nonblock(); -// valkeySetDisconnectCallback(c,__test_callback,(void*)2); -// valkeyDisconnect(c); -// test_cond(__test_callback_flags == 2); -// valkeyFree(c); -// -// test("Calls disconnect callback and free callback on valkeyFree: "); -// c = __connect_nonblock(); -// valkeySetDisconnectCallback(c,__test_callback,(void*)2); -// valkeySetFreeCallback(c,__test_callback,(void*)4); -// valkeyFree(c); -// test_cond(__test_callback_flags == ((2 << 8) | 4)); -// -// test("valkeyBufferWrite against empty write buffer: "); -// c = __connect_nonblock(); -// test_cond(valkeyBufferWrite(c,&wdone) == VALKEY_OK && wdone == 1); -// valkeyFree(c); -// -// test("valkeyBufferWrite against not yet connected fd: "); -// c = __connect_nonblock(); -// valkeyCommand(c,"PING"); -// test_cond(valkeyBufferWrite(c,NULL) == VALKEY_ERR && -// strncmp(c->error,"write:",6) == 0); -// valkeyFree(c); -// -// test("valkeyBufferWrite against closed fd: "); -// c = __connect_nonblock(); -// valkeyCommand(c,"PING"); -// valkeyDisconnect(c); -// test_cond(valkeyBufferWrite(c,NULL) == VALKEY_ERR && -// strncmp(c->error,"write:",6) == 0); -// valkeyFree(c); -// -// test("Process callbacks in the right sequence: "); -// c = __connect_nonblock(); -// valkeyCommandWithCallback(c,__test_reply_callback,(void*)1,"PING"); -// valkeyCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); -// valkeyCommandWithCallback(c,__test_reply_callback,(void*)3,"PING"); -// -// /* Write output buffer */ -// wdone = 0; -// while(!wdone) { -// usleep(500); -// valkeyBufferWrite(c,&wdone); -// } -// -// /* Read until at least one callback is executed (the 3 replies will -// * arrive in a single packet, causing all callbacks to be executed in -// * a single pass). */ -// while(__test_callback_flags == 0) { -// assert(valkeyBufferRead(c) == VALKEY_OK); -// valkeyProcessCallbacks(c); -// } -// test_cond(__test_callback_flags == 0x010203); -// valkeyFree(c); -// -// test("valkeyDisconnect executes pending callbacks with NULL reply: "); -// c = __connect_nonblock(); -// valkeySetDisconnectCallback(c,__test_callback,(void*)1); -// valkeyCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); -// valkeyDisconnect(c); -// test_cond(__test_callback_flags == 0x0201); -// valkeyFree(c); -// } - #ifdef VALKEY_TEST_ASYNC #pragma GCC diagnostic ignored "-Woverlength-strings" /* required on gcc 4.8.x due to assert statements */