Skip to content

Commit

Permalink
More error tracing tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 10, 2024
1 parent ca11201 commit d64c59f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/redisx-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ static int rTransmitError(ClientPrivate *cp, const char *op) {
* @return X_SUCCESS (0) if successful, or else an appropriate error (see xchange.h).
*/
static int rReadChunkAsync(ClientPrivate *cp) {
static const char *fn = "rReadChunkAsync";

const int sock = cp->socket; // Local copy of socket fd that won't possibly change mid-call.

if(sock < 0) return X_NO_INIT;
if(sock < 0) return x_error(X_NO_INIT, ENOTCONN, fn, "clinet %d: not connected", cp->idx);

cp->next = 0;
cp->available = recv(sock, cp->in, REDISX_RCVBUF_SIZE, 0);
Expand Down Expand Up @@ -110,7 +112,7 @@ static int rReadToken(ClientPrivate *cp, char *buf, int length) {

if(!cp->isEnabled) {
pthread_mutex_unlock(&cp->readLock);
return x_error(X_NO_SERVICE, ENXIO, fn, "client is not connected");
return x_error(X_NO_SERVICE, ENOTCONN, fn, "client is not connected");
}

for(L=0; cp->isEnabled && foundTerms < 2; L++) {
Expand Down Expand Up @@ -147,7 +149,7 @@ static int rReadToken(ClientPrivate *cp, char *buf, int length) {
// If client was disabled before we got everything, then simply return X_NO_SERVICE
if(!cp->isEnabled) {
*buf = '\0';
return X_NO_SERVICE;
return x_trace(fn, NULL, X_NO_SERVICE);
}

// From here on L is the number of characters actually buffered.
Expand All @@ -166,7 +168,7 @@ static int rReadToken(ClientPrivate *cp, char *buf, int length) {
return L;
}

return foundTerms==2 ? L : x_error(REDIS_INCOMPLETE_TRANSFER, EIO, fn, "missing \\r\\n termination");
return foundTerms==2 ? L : x_error(REDIS_INCOMPLETE_TRANSFER, ENOMSG, fn, "missing \\r\\n termination");
}

/**
Expand All @@ -188,7 +190,7 @@ static int rReadBytes(ClientPrivate *cp, char *buf, int length) {

if(!cp->isEnabled) {
pthread_mutex_unlock(&cp->readLock);
return x_error(X_NO_SERVICE, ENXIO, fn, "client not connected");
return x_error(X_NO_SERVICE, ENOTCONN, fn, "client not connected");
}

for(L=0; cp->isEnabled && L<length; L++) {
Expand Down Expand Up @@ -224,19 +226,21 @@ static int rReadBytes(ClientPrivate *cp, char *buf, int length) {
*
*/
static int rSendBytesAsync(ClientPrivate *cp, const char *buf, int length, boolean isLast) {
static const char *fn = "rSendBytesAsync";

#if SEND_YIELD_COUNT > 0
static int count; // Total bytes sent;
#endif

const int sock = cp->socket; // Local copy of socket fd that won't possibly change mid-call.
char *from = (char *) buf; // Pointer to the next byte to send from buf...

if(!buf) return X_NULL;
if(!buf) return x_error(X_NULL, EINVAL, fn, "buffer is NULL");

trprintf(" >>> '%s'\n", buf);

if(!cp->isEnabled) return X_NO_INIT;
if(sock < 0) return X_NO_INIT;
if(!cp->isEnabled) return x_error(X_NO_INIT, ENOTCONN, fn, "client %d: disabled", cp->idx);
if(sock < 0) return x_error(X_NO_INIT, ENOTCONN, fn, "client %d: not connected", cp->idx);

while(length > 0) {
int n;
Expand Down Expand Up @@ -363,7 +367,7 @@ int redisxLockConnected(RedisClient *cl) {
cp = (ClientPrivate *) cl->priv;
if(!cp->isEnabled) {
redisxUnlockClient(cl);
return x_error(X_NO_SERVICE, ENXIO, fn, "client is not connected");
return x_error(X_NO_SERVICE, ENOTCONN, fn, "client is not connected");
}

return X_SUCCESS;
Expand Down

0 comments on commit d64c59f

Please sign in to comment.