summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-10-10 16:33:16 +0200
committerantirez <antirez@gmail.com>2014-10-10 16:36:09 +0200
commit29db3227ab8980f098080371ef57c4e1eeb38180 (patch)
treeb4897b55c92a93f7b6c4292f6a82ebdf63506ac1 /src
parent16546f5aca1236a179bff98af9aaee491cd6fd4d (diff)
downloadredis-29db3227ab8980f098080371ef57c4e1eeb38180.tar.gz
rio.c refactoring before adding a new target.
Diffstat (limited to 'src')
-rw-r--r--src/rio.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/rio.c b/src/rio.c
index 44f9b7a01..aa5061b75 100644
--- a/src/rio.c
+++ b/src/rio.c
@@ -55,6 +55,8 @@
#include "config.h"
#include "redis.h"
+/* ------------------------- Buffer I/O implementation ----------------------- */
+
/* Returns 1 or 0 for success/failure. */
static size_t rioBufferWrite(rio *r, const void *buf, size_t len) {
r->io.buffer.ptr = sdscatlen(r->io.buffer.ptr,(char*)buf,len);
@@ -76,6 +78,25 @@ static off_t rioBufferTell(rio *r) {
return r->io.buffer.pos;
}
+static const rio rioBufferIO = {
+ rioBufferRead,
+ rioBufferWrite,
+ rioBufferTell,
+ NULL, /* update_checksum */
+ 0, /* current checksum */
+ 0, /* bytes read or written */
+ 0, /* read/write chunk size */
+ { { NULL, 0 } } /* union for io-specific vars */
+};
+
+void rioInitWithBuffer(rio *r, sds s) {
+ *r = rioBufferIO;
+ r->io.buffer.ptr = s;
+ r->io.buffer.pos = 0;
+}
+
+/* --------------------- Stdio file pointer implementation ------------------- */
+
/* Returns 1 or 0 for success/failure. */
static size_t rioFileWrite(rio *r, const void *buf, size_t len) {
size_t retval;
@@ -103,17 +124,6 @@ static off_t rioFileTell(rio *r) {
return ftello(r->io.file.fp);
}
-static const rio rioBufferIO = {
- rioBufferRead,
- rioBufferWrite,
- rioBufferTell,
- NULL, /* update_checksum */
- 0, /* current checksum */
- 0, /* bytes read or written */
- 0, /* read/write chunk size */
- { { NULL, 0 } } /* union for io-specific vars */
-};
-
static const rio rioFileIO = {
rioFileRead,
rioFileWrite,
@@ -132,11 +142,7 @@ void rioInitWithFile(rio *r, FILE *fp) {
r->io.file.autosync = 0;
}
-void rioInitWithBuffer(rio *r, sds s) {
- *r = rioBufferIO;
- r->io.buffer.ptr = s;
- r->io.buffer.pos = 0;
-}
+/* ---------------------------- Generic functions ---------------------------- */
/* This function can be installed both in memory and file streams when checksum
* computation is needed. */
@@ -157,7 +163,8 @@ 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. */