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
97192e2d
Unverified
Commit
97192e2d
authored
Nov 22, 2018
by
Salvatore Sanfilippo
Committed by
GitHub
Nov 22, 2018
Browse files
Merge pull request #5569 from maximebedard/backport-4497
Backport #4497 to redis 4
parents
54b17f98
1908aba7
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
97192e2d
...
...
@@ -67,6 +67,16 @@ int listMatchObjects(void *a, void *b) {
return
equalStringObjects
(
a
,
b
);
}
/* This function links the client to the global linked list of clients.
* unlinkClient() does the opposite, among other things. */
void
linkClient
(
client
*
c
)
{
listAddNodeTail
(
server
.
clients
,
c
);
/* Note that we remember the linked list node where the client is stored,
* this way removing the client in unlinkClient() will not require
* a linear scan, but just a constant time operation. */
c
->
client_list_node
=
listLast
(
server
.
clients
);
}
client
*
createClient
(
int
fd
)
{
client
*
c
=
zmalloc
(
sizeof
(
client
));
...
...
@@ -133,9 +143,10 @@ client *createClient(int fd) {
c
->
pubsub_channels
=
dictCreate
(
&
objectKeyPointerValueDictType
,
NULL
);
c
->
pubsub_patterns
=
listCreate
();
c
->
peerid
=
NULL
;
c
->
client_list_node
=
NULL
;
listSetFreeMethod
(
c
->
pubsub_patterns
,
decrRefCountVoid
);
listSetMatchMethod
(
c
->
pubsub_patterns
,
listMatchObjects
);
if
(
fd
!=
-
1
)
li
stAddNodeTail
(
server
.
c
lient
s
,
c
);
if
(
fd
!=
-
1
)
li
nkC
lient
(
c
);
initClientMultiState
(
c
);
return
c
;
}
...
...
@@ -752,9 +763,10 @@ void unlinkClient(client *c) {
* fd is already set to -1. */
if
(
c
->
fd
!=
-
1
)
{
/* Remove from the list of active clients. */
ln
=
listSearchKey
(
server
.
clients
,
c
);
serverAssert
(
ln
!=
NULL
);
listDelNode
(
server
.
clients
,
ln
);
if
(
c
->
client_list_node
)
{
listDelNode
(
server
.
clients
,
c
->
client_list_node
);
c
->
client_list_node
=
NULL
;
}
/* Unregister async I/O handlers and close the socket. */
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_READABLE
);
...
...
src/replication.c
View file @
97192e2d
...
...
@@ -2226,7 +2226,7 @@ void replicationResurrectCachedMaster(int newfd) {
server
.
repl_down_since
=
0
;
/* Re-add to the list of clients. */
li
stAddNodeTail
(
server
.
c
lient
s
,
server
.
master
);
li
nkC
lient
(
server
.
master
);
if
(
aeCreateFileEvent
(
server
.
el
,
newfd
,
AE_READABLE
,
readQueryFromClient
,
server
.
master
))
{
serverLog
(
LL_WARNING
,
"Error resurrecting the cached master, impossible to add the readable handler: %s"
,
strerror
(
errno
));
...
...
src/server.h
View file @
97192e2d
...
...
@@ -723,6 +723,7 @@ typedef struct client {
dict
*
pubsub_channels
;
/* channels a client is interested in (SUBSCRIBE) */
list
*
pubsub_patterns
;
/* patterns a client is interested in (SUBSCRIBE) */
sds
peerid
;
/* Cached peer ID. */
listNode
*
client_list_node
;
/* list node in client list */
/* Response buffer */
int
bufpos
;
...
...
@@ -1393,6 +1394,7 @@ int handleClientsWithPendingWrites(void);
int
clientHasPendingReplies
(
client
*
c
);
void
unlinkClient
(
client
*
c
);
int
writeToClient
(
int
fd
,
client
*
c
,
int
handler_installed
);
void
linkClient
(
client
*
c
);
#ifdef __GNUC__
void
addReplyErrorFormat
(
client
*
c
,
const
char
*
fmt
,
...)
...
...
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