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
b741a90c
Commit
b741a90c
authored
Sep 28, 2015
by
antirez
Browse files
handleClientsWithPendingWrites(): detect dead clients.
parent
481a0db3
Changes
1
Show whitespace changes
Inline
Side-by-side
src/networking.c
View file @
b741a90c
...
@@ -816,14 +816,13 @@ void freeClientsInAsyncFreeQueue(void) {
...
@@ -816,14 +816,13 @@ void freeClientsInAsyncFreeQueue(void) {
}
}
}
}
void
sendReplyToClient
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
/* Write data in output buffers to client. Return C_OK if the client
client
*
c
=
privdata
;
* is still valid after the call, C_ERR if it was freed. */
int
writeToClient
(
int
fd
,
client
*
c
)
{
ssize_t
nwritten
=
0
,
totwritten
=
0
;
ssize_t
nwritten
=
0
,
totwritten
=
0
;
size_t
objlen
;
size_t
objlen
;
size_t
objmem
;
size_t
objmem
;
robj
*
o
;
robj
*
o
;
UNUSED
(
el
);
UNUSED
(
mask
);
while
(
c
->
bufpos
>
0
||
listLength
(
c
->
reply
))
{
while
(
c
->
bufpos
>
0
||
listLength
(
c
->
reply
))
{
if
(
c
->
bufpos
>
0
)
{
if
(
c
->
bufpos
>
0
)
{
...
@@ -881,7 +880,7 @@ void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -881,7 +880,7 @@ void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
serverLog
(
LL_VERBOSE
,
serverLog
(
LL_VERBOSE
,
"Error writing to client: %s"
,
strerror
(
errno
));
"Error writing to client: %s"
,
strerror
(
errno
));
freeClient
(
c
);
freeClient
(
c
);
return
;
return
C_ERR
;
}
}
}
}
if
(
totwritten
>
0
)
{
if
(
totwritten
>
0
)
{
...
@@ -896,8 +895,19 @@ void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -896,8 +895,19 @@ void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
);
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
);
/* Close connection after entire reply has been sent. */
/* Close connection after entire reply has been sent. */
if
(
c
->
flags
&
CLIENT_CLOSE_AFTER_REPLY
)
freeClient
(
c
);
if
(
c
->
flags
&
CLIENT_CLOSE_AFTER_REPLY
)
{
freeClient
(
c
);
return
C_ERR
;
}
}
}
return
C_OK
;
}
/* Write event handler. Just send data to the client. */
void
sendReplyToClient
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
UNUSED
(
el
);
UNUSED
(
mask
);
writeToClient
(
fd
,
privdata
);
}
}
/* This function is called just before entering the event loop, in the hope
/* This function is called just before entering the event loop, in the hope
...
@@ -915,7 +925,7 @@ void handleClientsWithPendingWrites(void) {
...
@@ -915,7 +925,7 @@ void handleClientsWithPendingWrites(void) {
listDelNode
(
server
.
clients_pending_write
,
ln
);
listDelNode
(
server
.
clients_pending_write
,
ln
);
/* Try to write buffers to the client socket. */
/* Try to write buffers to the client socket. */
sendReplyToClient
(
server
.
el
,
c
->
fd
,
c
,
0
)
;
if
(
writeToClient
(
c
->
fd
,
c
)
==
C_ERR
)
continue
;
/* If there is nothing left, do nothing. Otherwise install
/* If there is nothing left, do nothing. Otherwise install
* the write handler. */
* the write handler. */
...
...
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