From d9d026db7ea19c9d523b37a8f7cc9b4bd5a52f79 Mon Sep 17 00:00:00 2001 From: Attila Kovacs Date: Thu, 5 Sep 2024 13:59:16 +0200 Subject: [PATCH] Refactor some macros for more consistent naming and site update --- README.md | 4 ++-- include/redisx-priv.h | 2 +- include/redisx.h | 24 ++++++++++++------------ src/redisx-client.c | 8 ++++---- src/redisx-net.c | 6 +++--- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 2a5fe62..c7afad4 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ prior to invoking `make`. The following build variables can be configured: - `LDFLAGS`: Linker flags (default is `-lm`). Note, `-lxchange` will be added automatically. - `BUILD_MODE`: You can set it to `debug` to enable debugging features: it will initialize the global `xDebug` - variable to `TRUE`) and add `-g` to `CFLAGS`. + variable to `TRUE` and add `-g` to `CFLAGS`. - `CHECKEXTRA`: Extra options to pass to `cppcheck` for the `make check` target @@ -749,7 +749,7 @@ atomically. Such an execution block in RedisX may look something like: RESP *result; // Obtain a lock on the client on which to execute the block. - // e.g. the INTERACTIVE_CHANNEL + // e.g. the interactive client channel. RedisClient *cl = redisxGetLockedConnectedClient(redis, REDISX_INTERACTIVE_CHANNEL); if (cl == NULL) { // Abort: we don't have exclusive access to the client diff --git a/include/redisx-priv.h b/include/redisx-priv.h index 1714574..5994926 100644 --- a/include/redisx-priv.h +++ b/include/redisx-priv.h @@ -44,7 +44,7 @@ typedef struct { pthread_mutex_t writeLock; ///< A lock for writing and requests through this channel... pthread_mutex_t readLock; ///< A lock for reading from the channel... pthread_mutex_t pendingLock; ///< A lock for updating pendingRequests... - char in[REDIS_RCV_CHUNK_SIZE]; ///< Local input buffer + char in[REDISX_RCVBUF_SIZE]; ///< Local input buffer int available; ///< Number of bytes available in the buffer. int next; ///< Index of next unconsumed byte in buffer. int socket; ///< Changing the socket should require both locks! diff --git a/include/redisx.h b/include/redisx.h index 6eee42d..5c1f269 100644 --- a/include/redisx.h +++ b/include/redisx.h @@ -16,24 +16,24 @@ #include "xchange.h" // Configuration constants -------------------------------------------------------> -#ifndef REDIS_TCP_PORT +#ifndef REDISX_TCP_PORT /// Default TCP/IP port on which Redis server listens to clients. -# define REDIS_TCP_PORT 6379 +# define REDISX_TCP_PORT 6379 #endif -#ifndef REDIS_TCP_BUF +#ifndef REDISX_TCP_BUF_SIZE /// (bytes) Default TCP buffer size (send/recv) for Redis clients. Values <= 0 will use system default. -# define REDIS_TCP_BUF 0 +# define REDISX_TCP_BUF_SIZE 0 #endif -#ifndef REDIS_CMDBUF_SIZE +#ifndef REDISX_CMDBUF_SIZE /// (bytes) Size of many internal arrays, and the max. send chunk size. At least ~16 bytes... -# define REDIS_CMDBUF_SIZE 8192 +# define REDISX_CMDBUF_SIZE 8192 #endif -#ifndef REDIS_RCV_CHUNK_SIZE +#ifndef REDISX_RCVBUF_SIZE /// (bytes) Redis receive buffer size (at most that much is read from the socket in a single call). -# define REDIS_RCV_CHUNK_SIZE 8192 +# define REDISX_RCVBUF_SIZE 8192 #endif #ifndef REDISX_SET_LISTENER_PRIORITY @@ -92,7 +92,7 @@ #define RESP_BULK_STRING '$' ///< \hideinitializer RESP bulk string type #define RESP_PONG 'P' ///< \hideinitializer RESP PONG response type -#define REDIS_INVALID_CHANNEL (-101) ///< \hideinitializer There is no such channel in the Redis intance. +#define REDIS_INVALID_CHANNEL (-101) ///< \hideinitializer There is no such channel in the Redis instance. #define REDIS_NULL (-102) ///< \hideinitializer Redis returned NULL #define REDIS_ERROR (-103) ///< \hideinitializer Redis returned an error #define REDIS_INCOMPLETE_TRANSFER (-104) ///< \hideinitializer The transfer to/from Redis is incomplete @@ -107,9 +107,9 @@ * when connecting to the server; and the subscription client is connected as needed to process PUB/SUB requests. */ enum redisx_channel { - REDISX_INTERACTIVE_CHANNEL = 0, ///< \hideinitializer Redis channel number for interactive queries - REDISX_PIPELINE_CHANNEL, ///< \hideinitializer Redis channel number for pipelined transfers - REDISX_SUBSCRIPTION_CHANNEL ///< \hideinitializer Redis channel number for PUB/SUB messages + REDISX_INTERACTIVE_CHANNEL = 0, ///< \hideinitializer Redis channel number for interactive queries + REDISX_PIPELINE_CHANNEL, ///< \hideinitializer Redis channel number for pipelined transfers + REDISX_SUBSCRIPTION_CHANNEL ///< \hideinitializer Redis channel number for PUB/SUB messages }; #define REDISX_CHANNELS (REDISX_SUBSCRIPTION_CHANNEL + 1) ///< \hideinitializer The number of channels a Redis instance has. diff --git a/src/redisx-client.c b/src/redisx-client.c index 279c566..0084fa7 100644 --- a/src/redisx-client.c +++ b/src/redisx-client.c @@ -74,7 +74,7 @@ static int rReadChunkAsync(ClientPrivate *cp) { if(sock < 0) return X_NO_INIT; cp->next = 0; - cp->available = recv(sock, cp->in, REDIS_RCV_CHUNK_SIZE, 0); + cp->available = recv(sock, cp->in, REDISX_RCVBUF_SIZE, 0); xdprintf(" ... read %d bytes from client %d socket.\n", cp->available, cp->idx); if(cp->available <= 0) { if(cp->available == 0) errno = ECONNRESET; // 0 return is remote cleared connection. So set ECONNRESET... @@ -580,7 +580,7 @@ int redisxSendRequestAsync(RedisClient *cl, const char *command, const char *arg */ int redisxSendArrayRequestAsync(RedisClient *cl, char *args[], int lengths[], int n) { const char *funcName = "redisxSendArrayRequestAsync()"; - char buf[REDIS_CMDBUF_SIZE]; + char buf[REDISX_CMDBUF_SIZE]; int status, i, L; ClientPrivate *cp; @@ -601,7 +601,7 @@ int redisxSendArrayRequestAsync(RedisClient *cl, char *args[], int lengths[], in // length of next RESP the bulk string component including \r\n\0 termination. L1 = l + 3; - if((L + L1) > REDIS_CMDBUF_SIZE) { + if((L + L1) > REDISX_CMDBUF_SIZE) { // If buf cannot include the next argument, then flush the buffer... status = rSendBytesAsync(cp, buf, L, FALSE); if(status) return redisxError(funcName, status); @@ -609,7 +609,7 @@ int redisxSendArrayRequestAsync(RedisClient *cl, char *args[], int lengths[], in L = 0; // If the next argument does not fit into the buffer, then send it piecemeal - if(L1 > REDIS_CMDBUF_SIZE) { + if(L1 > REDISX_CMDBUF_SIZE) { status = rSendBytesAsync(cp, args[i], l, FALSE); if(status) return redisxError(funcName, status); diff --git a/src/redisx-net.c b/src/redisx-net.c index 05282ce..f4e8682 100644 --- a/src/redisx-net.c +++ b/src/redisx-net.c @@ -45,7 +45,7 @@ typedef struct ServerLink { static ServerLink *serverList; static pthread_mutex_t serverLock = PTHREAD_MUTEX_INITIALIZER; -static int tcpBufSize = REDIS_TCP_BUF; +static int tcpBufSize = REDISX_TCP_BUF_SIZE; /** @@ -519,7 +519,7 @@ int rConnectClient(Redis *redis, enum redisx_channel channel) { cp = (ClientPrivate *) cl->priv; serverAddress.sin_family = AF_INET; - serverAddress.sin_port = htons(REDIS_TCP_PORT); + serverAddress.sin_port = htons(REDISX_TCP_PORT); serverAddress.sin_addr.s_addr = p->addr; memset(serverAddress.sin_zero, '\0', sizeof(serverAddress.sin_zero)); @@ -637,7 +637,7 @@ Redis *redisxInit(const char *server) { } p->addr = inet_addr((char *) ipAddress); - p->port = REDIS_TCP_PORT; + p->port = REDISX_TCP_PORT; l = (ServerLink *) calloc(1, sizeof(ServerLink)); l->redis = redis;