X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/b91d605a35c294573f0213c89c421d09b538c2b6..8df3dcada5e34c6a99666931ee6dcccd57685353:/src/replication.c diff --git a/src/replication.c b/src/replication.c index 363ce54a..7687206a 100644 --- a/src/replication.c +++ b/src/replication.c @@ -110,68 +110,6 @@ void replicationFeedMonitors(list *monitors, int dictid, robj **argv, int argc) decrRefCount(cmdobj); } -int syncWrite(int fd, char *ptr, ssize_t size, int timeout) { - ssize_t nwritten, ret = size; - time_t start = time(NULL); - - timeout++; - while(size) { - if (aeWait(fd,AE_WRITABLE,1000) & AE_WRITABLE) { - nwritten = write(fd,ptr,size); - if (nwritten == -1) return -1; - ptr += nwritten; - size -= nwritten; - } - if ((time(NULL)-start) > timeout) { - errno = ETIMEDOUT; - return -1; - } - } - return ret; -} - -int syncRead(int fd, char *ptr, ssize_t size, int timeout) { - ssize_t nread, totread = 0; - time_t start = time(NULL); - - timeout++; - while(size) { - if (aeWait(fd,AE_READABLE,1000) & AE_READABLE) { - nread = read(fd,ptr,size); - if (nread == -1) return -1; - ptr += nread; - size -= nread; - totread += nread; - } - if ((time(NULL)-start) > timeout) { - errno = ETIMEDOUT; - return -1; - } - } - return totread; -} - -int syncReadLine(int fd, char *ptr, ssize_t size, int timeout) { - ssize_t nread = 0; - - size--; - while(size) { - char c; - - if (syncRead(fd,&c,1,timeout) == -1) return -1; - if (c == '\n') { - *ptr = '\0'; - if (nread && *(ptr-1) == '\r') *(ptr-1) = '\0'; - return nread; - } else { - *ptr++ = c; - *ptr = '\0'; - nread++; - } - } - return nread; -} - void syncCommand(redisClient *c) { /* ignore SYNC if aleady slave or in monitor mode */ if (c->flags & REDIS_SLAVE) return; @@ -179,7 +117,7 @@ void syncCommand(redisClient *c) { /* Refuse SYNC requests if we are a slave but the link with our master * is not ok... */ if (server.masterhost && server.replstate != REDIS_REPL_CONNECTED) { - addReplySds(c,sdsnew("-ERR Can't SYNC while not connected with my master\r\n")); + addReplyError(c,"Can't SYNC while not connected with my master"); return; } @@ -188,7 +126,7 @@ void syncCommand(redisClient *c) { * buffer registering the differences between the BGSAVE and the current * dataset, so that we can copy to other slaves if needed. */ if (listLength(c->reply) != 0) { - addReplySds(c,sdsnew("-ERR SYNC is invalid with pending input\r\n")); + addReplyError(c,"SYNC is invalid with pending input"); return; } @@ -226,7 +164,7 @@ void syncCommand(redisClient *c) { redisLog(REDIS_NOTICE,"Starting BGSAVE for SYNC"); if (rdbSaveBackground(server.dbfilename) != REDIS_OK) { redisLog(REDIS_NOTICE,"Replication failed, can't BGSAVE"); - addReplySds(c,sdsnew("-ERR Unalbe to perform background save\r\n")); + addReplyError(c,"Unable to perform background save"); return; } c->replstate = REDIS_REPL_WAIT_BGSAVE_END;