summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Stancliff <matt@genges.com>2015-01-18 16:46:25 -0500
committerMatt Stancliff <matt@genges.com>2015-01-19 14:10:12 -0500
commit53c082ec39fb4daafba09e416279265f20d46006 (patch)
tree93f38d9c337f3cd9109311f3d4255dbe4712bc6b
parentf704360462640a88975eeb68fd80617921d7c97d (diff)
downloadredis-53c082ec39fb4daafba09e416279265f20d46006.tar.gz
Improve networking type correctness
read() and write() return ssize_t (signed long), not int. For other offsets, we can use the unsigned size_t type instead of a signed offset (since our replication offsets and buffer positions are never negative).
-rw-r--r--src/anet.c4
-rw-r--r--src/cluster.c2
-rw-r--r--src/networking.c5
-rw-r--r--src/redis-benchmark.c4
-rw-r--r--src/redis.h10
5 files changed, 13 insertions, 12 deletions
diff --git a/src/anet.c b/src/anet.c
index 76e9b67ae..0ec5c55a2 100644
--- a/src/anet.c
+++ b/src/anet.c
@@ -391,7 +391,7 @@ int anetUnixNonBlockConnect(char *err, char *path)
* (unless error or EOF condition is encountered) */
int anetRead(int fd, char *buf, int count)
{
- int nread, totlen = 0;
+ ssize_t nread, totlen = 0;
while(totlen != count) {
nread = read(fd,buf,count-totlen);
if (nread == 0) return totlen;
@@ -406,7 +406,7 @@ int anetRead(int fd, char *buf, int count)
* (unless error is encountered) */
int anetWrite(int fd, char *buf, int count)
{
- int nwritten, totlen = 0;
+ ssize_t nwritten, totlen = 0;
while(totlen != count) {
nwritten = write(fd,buf,count-totlen);
if (nwritten == 0) return totlen;
diff --git a/src/cluster.c b/src/cluster.c
index ec6901e8f..826c7f41d 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -4462,7 +4462,7 @@ try_again:
{
sds buf = cmd.io.buffer.ptr;
size_t pos = 0, towrite;
- int nwritten = 0;
+ ssize_t nwritten = 0;
while ((towrite = sdslen(buf)-pos) > 0) {
towrite = (towrite > (64*1024) ? (64*1024) : towrite);
diff --git a/src/networking.c b/src/networking.c
index 607d225fd..0b69f5408 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -797,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);
@@ -1621,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);
diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c
index 7567e0181..f735aeb63 100644
--- a/src/redis-benchmark.c
+++ b/src/redis-benchmark.c
@@ -86,7 +86,7 @@ typedef struct _client {
char **randptr; /* Pointers to :rand: strings inside the command buf */
size_t randlen; /* Number of pointers in client->randptr */
size_t randfree; /* Number of unused pointers in client->randptr */
- unsigned int written; /* Bytes of 'obuf' already written */
+ size_t written; /* Bytes of 'obuf' already written */
long long start; /* Start time of a request */
long long latency; /* Request latency */
int pending; /* Number of pending requests (replies to consume) */
@@ -266,7 +266,7 @@ static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
if (sdslen(c->obuf) > c->written) {
void *ptr = c->obuf+c->written;
- int nwritten = write(c->context->fd,ptr,sdslen(c->obuf)-c->written);
+ ssize_t nwritten = write(c->context->fd,ptr,sdslen(c->obuf)-c->written);
if (nwritten == -1) {
if (errno != EPIPE)
fprintf(stderr, "Writing to socket: %s\n", strerror(errno));
diff --git a/src/redis.h b/src/redis.h
index 0c191d06f..6a8308f78 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -542,8 +542,8 @@ typedef struct redisClient {
int multibulklen; /* number of multi bulk arguments left to read */
long bulklen; /* length of bulk argument in multi bulk request */
list *reply;
- unsigned long reply_bytes; /* Tot bytes of objects in reply list */
- int sentlen; /* Amount of bytes already sent in the current
+ size_t reply_bytes; /* Tot bytes of objects in reply list */
+ size_t sentlen; /* Amount of bytes already sent in the current
buffer or object being sent. */
time_t ctime; /* Client creation time */
time_t lastinteraction; /* time of the last interaction, used for timeout */
@@ -553,8 +553,8 @@ typedef struct redisClient {
int replstate; /* replication state if this is a slave */
int repl_put_online_on_ack; /* Install slave write handler on ACK. */
int repldbfd; /* replication DB file descriptor */
- off_t repldboff; /* replication DB file offset */
- off_t repldbsize; /* replication DB file size */
+ size_t repldboff; /* replication DB file offset */
+ size_t repldbsize; /* replication DB file size */
sds replpreamble; /* replication DB preamble. */
long long reploff; /* replication offset if this is our master */
long long repl_ack_off; /* replication ack offset, if this is a slave */
@@ -571,7 +571,7 @@ typedef struct redisClient {
sds peerid; /* Cached peer ID. */
/* Response buffer */
- int bufpos;
+ size_t bufpos;
char buf[REDIS_REPLY_CHUNK_BYTES];
} redisClient;