5555#include "config.h"
5656#include "redis.h"
5757
58+ /* ------------------------- Buffer I/O implementation ----------------------- */
59+
5860/* Returns 1 or 0 for success/failure. */
5961static size_t rioBufferWrite (rio * r , const void * buf , size_t len ) {
6062 r -> io .buffer .ptr = sdscatlen (r -> io .buffer .ptr ,(char * )buf ,len );
@@ -76,6 +78,25 @@ static off_t rioBufferTell(rio *r) {
7678 return r -> io .buffer .pos ;
7779}
7880
81+ static const rio rioBufferIO = {
82+ rioBufferRead ,
83+ rioBufferWrite ,
84+ rioBufferTell ,
85+ NULL , /* update_checksum */
86+ 0 , /* current checksum */
87+ 0 , /* bytes read or written */
88+ 0 , /* read/write chunk size */
89+ { { NULL , 0 } } /* union for io-specific vars */
90+ };
91+
92+ void rioInitWithBuffer (rio * r , sds s ) {
93+ * r = rioBufferIO ;
94+ r -> io .buffer .ptr = s ;
95+ r -> io .buffer .pos = 0 ;
96+ }
97+
98+ /* --------------------- Stdio file pointer implementation ------------------- */
99+
79100/* Returns 1 or 0 for success/failure. */
80101static size_t rioFileWrite (rio * r , const void * buf , size_t len ) {
81102 size_t retval ;
@@ -103,17 +124,6 @@ static off_t rioFileTell(rio *r) {
103124 return ftello (r -> io .file .fp );
104125}
105126
106- static const rio rioBufferIO = {
107- rioBufferRead ,
108- rioBufferWrite ,
109- rioBufferTell ,
110- NULL , /* update_checksum */
111- 0 , /* current checksum */
112- 0 , /* bytes read or written */
113- 0 , /* read/write chunk size */
114- { { NULL , 0 } } /* union for io-specific vars */
115- };
116-
117127static const rio rioFileIO = {
118128 rioFileRead ,
119129 rioFileWrite ,
@@ -132,11 +142,7 @@ void rioInitWithFile(rio *r, FILE *fp) {
132142 r -> io .file .autosync = 0 ;
133143}
134144
135- void rioInitWithBuffer (rio * r , sds s ) {
136- * r = rioBufferIO ;
137- r -> io .buffer .ptr = s ;
138- r -> io .buffer .pos = 0 ;
139- }
145+ /* ---------------------------- Generic functions ---------------------------- */
140146
141147/* This function can be installed both in memory and file streams when checksum
142148 * computation is needed. */
@@ -157,7 +163,8 @@ void rioSetAutoSync(rio *r, off_t bytes) {
157163 r -> io .file .autosync = bytes ;
158164}
159165
160- /* ------------------------------ Higher level interface ---------------------------
166+ /* --------------------------- Higher level interface --------------------------
167+ *
161168 * The following higher level functions use lower level rio.c functions to help
162169 * generating the Redis protocol for the Append Only File. */
163170
0 commit comments