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
hiredis
Commits
2defe232
Commit
2defe232
authored
Jan 10, 2012
by
Pieter Noordhuis
Browse files
Extract fd r/w to separate file
parent
f7097a17
Changes
3
Show whitespace changes
Inline
Side-by-side
fd.c
View file @
2defe232
...
...
@@ -33,6 +33,38 @@ int redis_fd_error(int fd) {
return
err
;
}
int
redis_fd_read
(
int
fildes
,
void
*
buf
,
size_t
nbyte
)
{
int
nread
;
do
{
nread
=
read
(
fildes
,
buf
,
nbyte
);
}
while
(
nread
==
-
1
&&
errno
==
EINTR
);
if
(
nread
==
-
1
)
{
return
REDIS_ESYS
;
}
if
(
nread
==
0
)
{
return
REDIS_EEOF
;
}
return
nread
;
}
int
redis_fd_write
(
int
fildes
,
const
void
*
buf
,
size_t
nbyte
)
{
int
nwritten
;
do
{
nwritten
=
write
(
fildes
,
buf
,
nbyte
);
}
while
(
nwritten
==
-
1
&&
errno
==
EINTR
);
if
(
nwritten
==
-
1
)
{
return
REDIS_ESYS
;
}
return
nwritten
;
}
static
int
redis__nonblock
(
int
fd
,
int
nonblock
)
{
int
flags
;
...
...
fd.h
View file @
2defe232
...
...
@@ -5,6 +5,8 @@
#include "address.h"
int
redis_fd_error
(
int
fd
);
int
redis_fd_read
(
int
fildes
,
void
*
buf
,
size_t
nbyte
);
int
redis_fd_write
(
int
fildes
,
const
void
*
buf
,
size_t
nbyte
);
int
redis_fd_connect_address
(
const
redis_address
addr
);
int
redis_fd_connect_gai
(
int
family
,
const
char
*
host
,
int
port
,
redis_address
*
addr
);
...
...
handle.c
View file @
2defe232
...
...
@@ -206,16 +206,13 @@ int redis_handle_write_from_buffer(redis_handle *h, int *drained) {
}
if
(
sdslen
(
h
->
wbuf
))
{
do
{
nwritten
=
write
(
h
->
fd
,
h
->
wbuf
,
sdslen
(
h
->
wbuf
));
}
while
(
nwritten
==
-
1
&&
errno
==
EINTR
);
if
(
nwritten
==
-
1
)
{
nwritten
=
redis_fd_write
(
h
->
fd
,
h
->
wbuf
,
sdslen
(
h
->
wbuf
));
if
(
nwritten
<
0
)
{
/* Let all errors bubble, including EAGAIN */
return
REDIS_ESYS
;
return
nwritten
;
}
if
(
nwritten
>
0
)
{
if
(
nwritten
)
{
h
->
wbuf
=
sdsrange
(
h
->
wbuf
,
nwritten
,
-
1
);
}
}
...
...
@@ -246,17 +243,9 @@ int redis_handle_read_to_buffer(redis_handle *h) {
return
REDIS_ESYS
;
}
do
{
nread
=
read
(
h
->
fd
,
buf
,
sizeof
(
buf
));
}
while
(
nread
==
-
1
&&
errno
==
EINTR
);
if
(
nread
==
-
1
)
{
/* Let all errors bubble, including EAGAIN */
return
REDIS_ESYS
;
}
if
(
nread
==
0
)
{
return
REDIS_EEOF
;
nread
=
redis_fd_read
(
h
->
fd
,
buf
,
sizeof
(
buf
));
if
(
nread
<
0
)
{
return
nread
;
}
h
->
rbuf
=
sdscatlen
(
h
->
rbuf
,
buf
,
nread
);
...
...
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