summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-12-13 15:53:31 +0100
committerantirez <antirez@gmail.com>2017-12-13 15:53:51 +0100
commitbf475ff358a42f06ef0ef91f4a23e3b6addaa09e (patch)
tree703104ecd8578b51afa2b9a9ed6ce5cda17c16c0
parent19ff6fb58295a5d87901b85d6aa6add9df10f1f2 (diff)
downloadredis-bf475ff358a42f06ef0ef91f4a23e3b6addaa09e.tar.gz
RIO: improve comments and fix lines over 80 cols.
-rw-r--r--src/rio.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/rio.c b/src/rio.c
index 93200b682..fb8985f7c 100644
--- a/src/rio.c
+++ b/src/rio.c
@@ -157,7 +157,11 @@ void rioInitWithFile(rio *r, FILE *fp) {
r->io.file.autosync = 0;
}
-/* ------------------- File descriptor implementation ------------------- */
+/* --------------------- File descriptor implementation ---------------------
+ * This RIO target is used when reading an RDB file from the network (when
+ * the diskless slave feature is enabled), so it implements a buffered read
+ * target, and does not implement writing.
+ * ------------------------------------------------------------------------ */
static size_t rioFdWrite(rio *r, const void *buf, size_t len) {
UNUSED(r);
@@ -170,25 +174,25 @@ static size_t rioFdWrite(rio *r, const void *buf, size_t len) {
static size_t rioFdRead(rio *r, void *buf, size_t len) {
size_t avail = sdslen(r->io.fd.buf)-r->io.fd.pos;
- /* if the buffer is too small for the entire request: realloc */
+ /* If the buffer is too small for the entire request: realloc */
if (sdslen(r->io.fd.buf) + sdsavail(r->io.fd.buf) < len)
r->io.fd.buf = sdsMakeRoomFor(r->io.fd.buf, len - sdslen(r->io.fd.buf));
- /* if the remaining unused buffer is not large enough: memmove so that we can read the rest */
+ /* If the remaining unused buffer is not large enough: memmove so that
+ * we can read the rest */
if (len > avail && sdsavail(r->io.fd.buf) < len - avail) {
sdsrange(r->io.fd.buf, r->io.fd.pos, -1);
r->io.fd.pos = 0;
}
- /* if we don't already have all the data in the sds, read more */
+ /* If we don't already have all the data in the sds, read more */
while (len > sdslen(r->io.fd.buf) - r->io.fd.pos) {
size_t buffered = sdslen(r->io.fd.buf) - r->io.fd.pos;
size_t toread = len - buffered;
- /* read either what's missing, or PROTO_IOBUF_LEN, the bigger of the two */
- if (toread < PROTO_IOBUF_LEN)
- toread = PROTO_IOBUF_LEN;
- if (toread > sdsavail(r->io.fd.buf))
- toread = sdsavail(r->io.fd.buf);
+ /* Read either what's missing, or PROTO_IOBUF_LEN, the bigger of the
+ * two */
+ if (toread < PROTO_IOBUF_LEN) toread = PROTO_IOBUF_LEN;
+ if (toread > sdsavail(r->io.fd.buf)) toread = sdsavail(r->io.fd.buf);
if (r->io.fd.read_limit != 0 &&
r->io.fd.read_so_far + buffered + toread > r->io.fd.read_limit) {
if (r->io.fd.read_limit >= r->io.fd.read_so_far - buffered)
@@ -198,7 +202,8 @@ static size_t rioFdRead(rio *r, void *buf, size_t len) {
return 0;
}
}
- int retval = read(r->io.fd.fd, (char*)r->io.fd.buf + sdslen(r->io.fd.buf), toread);
+ int retval = read(r->io.fd.fd,
+ (char*)r->io.fd.buf + sdslen(r->io.fd.buf), toread);
if (retval <= 0) {
if (errno == EWOULDBLOCK) errno = ETIMEDOUT;
return 0;
@@ -264,7 +269,12 @@ void rioFreeFd(rio *r, sds* out_remainingBufferedData) {
r->io.fd.buf = NULL;
}
-/* ------------------- File descriptors set implementation ------------------- */
+/* ------------------- File descriptors set implementation ------------------
+ * This RIO target is used for master-side diskless implementation, when we
+ * write our RDB file at the same time to multiple slaves that are waiting
+ * for a full SYNC. Reading from this target is not implemented because is
+ * never used.
+ * ------------------------------------------------------------------------ */
/* Returns 1 or 0 for success/failure.
* The function returns success as long as we are able to correctly write
@@ -390,7 +400,7 @@ void rioFreeFdset(rio *r) {
sdsfree(r->io.fdset.buf);
}
-/* ---------------------------- Generic functions ---------------------------- */
+/* ---------------------------- Generic functions --------------------------- */
/* This function can be installed both in memory and file streams when checksum
* computation is needed. */
@@ -411,7 +421,7 @@ void rioSetAutoSync(rio *r, off_t bytes) {
r->io.file.autosync = bytes;
}
-/* --------------------------- Higher level interface --------------------------
+/* --------------------------- Higher level interface -------------------------
*
* The following higher level functions use lower level rio.c functions to help
* generating the Redis protocol for the Append Only File. */