Skip to content

Commit

Permalink
Refactor some macros for more consistent naming and site update
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 5, 2024
1 parent 66fb15c commit d9d026d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/redisx-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
24 changes: 12 additions & 12 deletions include/redisx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &lt;= 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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/redisx-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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;

Expand All @@ -601,15 +601,15 @@ 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);

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);

Expand Down
6 changes: 3 additions & 3 deletions src/redisx-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d9d026d

Please sign in to comment.