diff options
Diffstat (limited to 'src/networking.c')
-rw-r--r-- | src/networking.c | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/src/networking.c b/src/networking.c index 5a780a597..0b69f5408 100644 --- a/src/networking.c +++ b/src/networking.c @@ -525,6 +525,14 @@ void addReplyBulkCBuffer(redisClient *c, void *p, size_t len) { addReply(c,shared.crlf); } +/* Add sds to reply (takes ownership of sds and frees it) */ +void addReplyBulkSds(redisClient *c, sds s) { + addReplySds(c,sdscatfmt(sdsempty(),"$%u\r\n", + (unsigned long)sdslen(s))); + addReplySds(c,s); + addReply(c,shared.crlf); +} + /* Add a C nul term string as bulk reply */ void addReplyBulkCString(redisClient *c, char *s) { if (s == NULL) { @@ -789,7 +797,8 @@ void freeClientsInAsyncFreeQueue(void) { void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) { redisClient *c = privdata; - int nwritten = 0, totwritten = 0, objlen; + ssize_t nwritten = 0, totwritten = 0; + size_t objlen; size_t objmem; robj *o; REDIS_NOTUSED(el); @@ -1219,17 +1228,6 @@ void getClientsMaxBuffers(unsigned long *longest_output_list, *biggest_input_buffer = bib; } -/* This is a helper function for genClientPeerId(). - * It writes the specified ip/port to "peerid" as a null termiated string - * in the form ip:port if ip does not contain ":" itself, otherwise - * [ip]:port format is used (for IPv6 addresses basically). */ -void formatPeerId(char *peerid, size_t peerid_len, char *ip, int port) { - if (strchr(ip,':')) - snprintf(peerid,peerid_len,"[%s]:%d",ip,port); - else - snprintf(peerid,peerid_len,"%s:%d",ip,port); -} - /* A Redis "Peer ID" is a colon separated ip:port pair. * For IPv4 it's in the form x.y.z.k:port, example: "127.0.0.1:1234". * For IPv6 addresses we use [] around the IP part, like in "[::1]:1234". @@ -1238,24 +1236,17 @@ void formatPeerId(char *peerid, size_t peerid_len, char *ip, int port) { * A Peer ID always fits inside a buffer of REDIS_PEER_ID_LEN bytes, including * the null term. * - * The function returns REDIS_OK on succcess, and REDIS_ERR on failure. - * * On failure the function still populates 'peerid' with the "?:0" string * in case you want to relax error checking or need to display something * anyway (see anetPeerToString implementation for more info). */ -int genClientPeerId(redisClient *client, char *peerid, size_t peerid_len) { - char ip[REDIS_IP_STR_LEN]; - int port; - +void genClientPeerId(redisClient *client, char *peerid, + size_t peerid_len) { if (client->flags & REDIS_UNIX_SOCKET) { /* Unix socket client. */ snprintf(peerid,peerid_len,"%s:0",server.unixsocket); - return REDIS_OK; } else { /* TCP client. */ - int retval = anetPeerToString(client->fd,ip,sizeof(ip),&port); - formatPeerId(peerid,peerid_len,ip,port); - return (retval == -1) ? REDIS_ERR : REDIS_OK; + anetFormatPeer(client->fd,peerid,peerid_len); } } @@ -1631,7 +1622,7 @@ int checkClientOutputBufferLimits(redisClient *c) { * called from contexts where the client can't be freed safely, i.e. from the * lower level functions pushing data inside the client output buffers. */ void asyncCloseClientOnOutputBufferLimitReached(redisClient *c) { - redisAssert(c->reply_bytes < ULONG_MAX-(1024*64)); + redisAssert(c->reply_bytes < SIZE_MAX-(1024*64)); if (c->reply_bytes == 0 || c->flags & REDIS_CLOSE_ASAP) return; if (checkClientOutputBufferLimits(c)) { sds client = catClientInfoString(sdsempty(),c); |