diff options
Diffstat (limited to 'src/syncio.c')
-rw-r--r-- | src/syncio.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/syncio.c b/src/syncio.c index b2843d5fb..48e0a0b79 100644 --- a/src/syncio.c +++ b/src/syncio.c @@ -118,7 +118,9 @@ ssize_t syncRead(int fd, char *ptr, ssize_t size, long long timeout) { } /* Read a line making sure that every char will not require more than 'timeout' - * milliseconds to be read. + * milliseconds to be read. Empty newlines before the first non-empty line + * are ignored. This is useful because since Redis sometimes uses empty + * newlines in order to take the connection "alive". * * On success the number of bytes read is returned, otherwise -1. * On success the string is always correctly terminated with a 0 byte. */ @@ -131,9 +133,12 @@ ssize_t syncReadLine(int fd, char *ptr, ssize_t size, long long timeout) { if (syncRead(fd,&c,1,timeout) == -1) return -1; if (c == '\n') { - *ptr = '\0'; - if (nread && *(ptr-1) == '\r') *(ptr-1) = '\0'; - return nread; + /* Ignore empty lines, otherwise return to the caller. */ + if (nread != 0) { + *ptr = '\0'; + if (nread && *(ptr-1) == '\r') *(ptr-1) = '\0'; + return nread; + } } else { *ptr++ = c; *ptr = '\0'; |