Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
29db3227
Commit
29db3227
authored
Oct 10, 2014
by
antirez
Browse files
rio.c refactoring before adding a new target.
parent
16546f5a
Changes
1
Show whitespace changes
Inline
Side-by-side
src/rio.c
View file @
29db3227
...
@@ -55,6 +55,8 @@
...
@@ -55,6 +55,8 @@
#include "config.h"
#include "config.h"
#include "redis.h"
#include "redis.h"
/* ------------------------- Buffer I/O implementation ----------------------- */
/* Returns 1 or 0 for success/failure. */
/* Returns 1 or 0 for success/failure. */
static
size_t
rioBufferWrite
(
rio
*
r
,
const
void
*
buf
,
size_t
len
)
{
static
size_t
rioBufferWrite
(
rio
*
r
,
const
void
*
buf
,
size_t
len
)
{
r
->
io
.
buffer
.
ptr
=
sdscatlen
(
r
->
io
.
buffer
.
ptr
,(
char
*
)
buf
,
len
);
r
->
io
.
buffer
.
ptr
=
sdscatlen
(
r
->
io
.
buffer
.
ptr
,(
char
*
)
buf
,
len
);
...
@@ -76,6 +78,25 @@ static off_t rioBufferTell(rio *r) {
...
@@ -76,6 +78,25 @@ static off_t rioBufferTell(rio *r) {
return
r
->
io
.
buffer
.
pos
;
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. */
/* Returns 1 or 0 for success/failure. */
static
size_t
rioFileWrite
(
rio
*
r
,
const
void
*
buf
,
size_t
len
)
{
static
size_t
rioFileWrite
(
rio
*
r
,
const
void
*
buf
,
size_t
len
)
{
size_t
retval
;
size_t
retval
;
...
@@ -103,17 +124,6 @@ static off_t rioFileTell(rio *r) {
...
@@ -103,17 +124,6 @@ static off_t rioFileTell(rio *r) {
return
ftello
(
r
->
io
.
file
.
fp
);
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
=
{
static
const
rio
rioFileIO
=
{
rioFileRead
,
rioFileRead
,
rioFileWrite
,
rioFileWrite
,
...
@@ -132,11 +142,7 @@ void rioInitWithFile(rio *r, FILE *fp) {
...
@@ -132,11 +142,7 @@ void rioInitWithFile(rio *r, FILE *fp) {
r
->
io
.
file
.
autosync
=
0
;
r
->
io
.
file
.
autosync
=
0
;
}
}
void
rioInitWithBuffer
(
rio
*
r
,
sds
s
)
{
/* ---------------------------- Generic functions ---------------------------- */
*
r
=
rioBufferIO
;
r
->
io
.
buffer
.
ptr
=
s
;
r
->
io
.
buffer
.
pos
=
0
;
}
/* This function can be installed both in memory and file streams when checksum
/* This function can be installed both in memory and file streams when checksum
* computation is needed. */
* computation is needed. */
...
@@ -157,7 +163,8 @@ void rioSetAutoSync(rio *r, off_t bytes) {
...
@@ -157,7 +163,8 @@ void rioSetAutoSync(rio *r, off_t bytes) {
r
->
io
.
file
.
autosync
=
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
* The following higher level functions use lower level rio.c functions to help
* generating the Redis protocol for the Append Only File. */
* generating the Redis protocol for the Append Only File. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment