Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
c469f6ad
Commit
c469f6ad
authored
Oct 15, 2019
by
Yossi Gottlieb
Browse files
Code review minor changes (names, comments).
parent
71f10de4
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/ae.c
View file @
c469f6ad
...
@@ -99,7 +99,7 @@ int aeGetSetSize(aeEventLoop *eventLoop) {
...
@@ -99,7 +99,7 @@ int aeGetSetSize(aeEventLoop *eventLoop) {
}
}
/* Tells the next iteration/s of the event processing to set timeout of 0. */
/* Tells the next iteration/s of the event processing to set timeout of 0. */
void
aeDontWait
(
aeEventLoop
*
eventLoop
,
int
noWait
)
{
void
ae
Set
DontWait
(
aeEventLoop
*
eventLoop
,
int
noWait
)
{
if
(
noWait
)
if
(
noWait
)
eventLoop
->
flags
|=
AE_DONT_WAIT
;
eventLoop
->
flags
|=
AE_DONT_WAIT
;
else
else
...
...
src/ae.h
View file @
c469f6ad
...
@@ -129,6 +129,6 @@ void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep
...
@@ -129,6 +129,6 @@ void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep
void
aeSetAfterSleepProc
(
aeEventLoop
*
eventLoop
,
aeBeforeSleepProc
*
aftersleep
);
void
aeSetAfterSleepProc
(
aeEventLoop
*
eventLoop
,
aeBeforeSleepProc
*
aftersleep
);
int
aeGetSetSize
(
aeEventLoop
*
eventLoop
);
int
aeGetSetSize
(
aeEventLoop
*
eventLoop
);
int
aeResizeSetSize
(
aeEventLoop
*
eventLoop
,
int
setsize
);
int
aeResizeSetSize
(
aeEventLoop
*
eventLoop
,
int
setsize
);
void
aeDontWait
(
aeEventLoop
*
eventLoop
,
int
noWait
);
void
ae
Set
DontWait
(
aeEventLoop
*
eventLoop
,
int
noWait
);
#endif
#endif
src/connection.c
View file @
c469f6ad
...
@@ -191,6 +191,11 @@ static int connSocketAccept(connection *conn, ConnectionCallbackFunc accept_hand
...
@@ -191,6 +191,11 @@ static int connSocketAccept(connection *conn, ConnectionCallbackFunc accept_hand
/* Register a write handler, to be called when the connection is writable.
/* Register a write handler, to be called when the connection is writable.
* If NULL, the existing handler is removed.
* If NULL, the existing handler is removed.
*
* The barrier flag indicates a write barrier is requested, resulting with
* CONN_FLAG_WRITE_BARRIER set. This will ensure that the write handler is
* always called before and not after the read handler in a single event
* loop.
*/
*/
static
int
connSocketSetWriteHandler
(
connection
*
conn
,
ConnectionCallbackFunc
func
,
int
barrier
)
{
static
int
connSocketSetWriteHandler
(
connection
*
conn
,
ConnectionCallbackFunc
func
,
int
barrier
)
{
if
(
func
==
conn
->
write_handler
)
return
C_OK
;
if
(
func
==
conn
->
write_handler
)
return
C_OK
;
...
@@ -250,7 +255,7 @@ static void connSocketEventHandler(struct aeEventLoop *el, int fd, void *clientD
...
@@ -250,7 +255,7 @@ static void connSocketEventHandler(struct aeEventLoop *el, int fd, void *clientD
}
}
/* Normally we execute the readable event first, and the writable
/* Normally we execute the readable event first, and the writable
* event la
s
ter. This is useful as sometimes we may be able
* event later. This is useful as sometimes we may be able
* to serve the reply of a query immediately after processing the
* to serve the reply of a query immediately after processing the
* query.
* query.
*
*
...
@@ -258,7 +263,7 @@ static void connSocketEventHandler(struct aeEventLoop *el, int fd, void *clientD
...
@@ -258,7 +263,7 @@ static void connSocketEventHandler(struct aeEventLoop *el, int fd, void *clientD
* asking us to do the reverse: never fire the writable event
* asking us to do the reverse: never fire the writable event
* after the readable. In such a case, we invert the calls.
* after the readable. In such a case, we invert the calls.
* This is useful when, for instance, we want to do things
* This is useful when, for instance, we want to do things
* in the beforeSleep() hook, like fsync
h
ing a file to disk,
* in the beforeSleep() hook, like fsync
'
ing a file to disk,
* before replying to a client. */
* before replying to a client. */
int
invert
=
conn
->
flags
&
CONN_FLAG_WRITE_BARRIER
;
int
invert
=
conn
->
flags
&
CONN_FLAG_WRITE_BARRIER
;
...
...
src/connhelpers.h
View file @
c469f6ad
...
@@ -33,10 +33,29 @@
...
@@ -33,10 +33,29 @@
#include "connection.h"
#include "connection.h"
/* These are helper functions that are common to different connection
* implementations (currently sockets in connection.c and TLS in tls.c).
*
* Currently helpers implement the mechanisms for invoking connection
* handlers, tracking in-handler states and dealing with deferred
* destruction (if invoked by a handler).
*/
/* Called whenever a handler is invoked on a connection and sets the
* CONN_FLAG_IN_HANDLER flag to indicate we're in a handler context.
*
* An attempt to close a connection while CONN_FLAG_IN_HANDLER is
* set will result with deferred close, i.e. setting the CONN_FLAG_CLOSE_SCHEDULED
* instead of destructing it.
*/
static
inline
void
enterHandler
(
connection
*
conn
)
{
static
inline
void
enterHandler
(
connection
*
conn
)
{
conn
->
flags
|=
CONN_FLAG_IN_HANDLER
;
conn
->
flags
|=
CONN_FLAG_IN_HANDLER
;
}
}
/* Called whenever a handler returns. This unsets the CONN_FLAG_IN_HANDLER
* flag and performs actual close/destruction if a deferred close was
* scheduled by the handler.
*/
static
inline
int
exitHandler
(
connection
*
conn
)
{
static
inline
int
exitHandler
(
connection
*
conn
)
{
conn
->
flags
&=
~
CONN_FLAG_IN_HANDLER
;
conn
->
flags
&=
~
CONN_FLAG_IN_HANDLER
;
if
(
conn
->
flags
&
CONN_FLAG_CLOSE_SCHEDULED
)
{
if
(
conn
->
flags
&
CONN_FLAG_CLOSE_SCHEDULED
)
{
...
@@ -46,6 +65,12 @@ static inline int exitHandler(connection *conn) {
...
@@ -46,6 +65,12 @@ static inline int exitHandler(connection *conn) {
return
1
;
return
1
;
}
}
/* Helper for connection implementations to call handlers:
* 1. Mark the handler in use.
* 2. Execute the handler (if set).
* 3. Mark the handler as NOT in use and perform deferred close if was
* requested by the handler at any time.
*/
static
inline
int
callHandler
(
connection
*
conn
,
ConnectionCallbackFunc
handler
)
{
static
inline
int
callHandler
(
connection
*
conn
,
ConnectionCallbackFunc
handler
)
{
conn
->
flags
|=
CONN_FLAG_IN_HANDLER
;
conn
->
flags
|=
CONN_FLAG_IN_HANDLER
;
if
(
handler
)
handler
(
conn
);
if
(
handler
)
handler
(
conn
);
...
...
src/rdb.c
View file @
c469f6ad
...
@@ -2365,8 +2365,8 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) {
...
@@ -2365,8 +2365,8 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) {
if
(
server
.
rdb_pipe_conns
)
return
C_ERR
;
if
(
server
.
rdb_pipe_conns
)
return
C_ERR
;
/* Before to fork, create a pipe that is used to transfer the rdb bytes to
/* Before to fork, create a pipe that is used to transfer the rdb bytes to
* the par
a
nt, we can't let it write directly to the sockets, since in case
* the par
e
nt, we can't let it write directly to the sockets, since in case
* of TLS we must let the parent handle a contin
e
ous TLS state when the
* of TLS we must let the parent handle a contin
u
ous TLS state when the
* child terminates and parent takes over. */
* child terminates and parent takes over. */
if
(
pipe
(
pipefds
)
==
-
1
)
return
C_ERR
;
if
(
pipe
(
pipefds
)
==
-
1
)
return
C_ERR
;
server
.
rdb_pipe_read
=
pipefds
[
0
];
server
.
rdb_pipe_read
=
pipefds
[
0
];
...
...
src/server.c
View file @
c469f6ad
...
@@ -2051,7 +2051,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
...
@@ -2051,7 +2051,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
/* Handle TLS pending data. (must be done before flushAppendOnlyFile) */
/* Handle TLS pending data. (must be done before flushAppendOnlyFile) */
tlsProcessPendingData
();
tlsProcessPendingData
();
/* If tls still has pending unread data don't sleep at all. */
/* If tls still has pending unread data don't sleep at all. */
aeDontWait
(
server
.
el
,
tlsHasPendingData
());
ae
Set
DontWait
(
server
.
el
,
tlsHasPendingData
());
/* Call the Redis Cluster before sleep function. Note that this function
/* Call the Redis Cluster before sleep function. Note that this function
* may change the state of Redis Cluster (from ok to fail or vice versa),
* may change the state of Redis Cluster (from ok to fail or vice versa),
...
...
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