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
57c5a766
Commit
57c5a766
authored
Nov 08, 2018
by
antirez
Browse files
RESP3: Aggregate deferred lengths functions.
parent
914ee431
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
57c5a766
...
...
@@ -416,28 +416,28 @@ void addReplyStatusFormat(client *c, const char *fmt, ...) {
/* Adds an empty object to the reply list that will contain the multi bulk
* length, which is not known when this function is called. */
void
*
addDeferred
MultiBulkLength
(
client
*
c
)
{
void
*
add
Reply
Deferred
Len
(
client
*
c
)
{
/* Note that we install the write event here even if the object is not
* ready to be sent, since we are sure that before returning to the
* event loop setDeferred
MultiBulkLength
() will be called. */
* event loop setDeferred
AggregateLen
() will be called. */
if
(
prepareClientToWrite
(
c
)
!=
C_OK
)
return
NULL
;
listAddNodeTail
(
c
->
reply
,
NULL
);
/* NULL is our placeholder. */
return
listLast
(
c
->
reply
);
}
/* Populate the length object and try gluing it to the next chunk. */
void
setDeferred
MultiBulkLength
(
client
*
c
,
void
*
node
,
long
length
)
{
void
setDeferred
AggregateLen
(
client
*
c
,
void
*
node
,
long
length
,
char
prefix
)
{
listNode
*
ln
=
(
listNode
*
)
node
;
clientReplyBlock
*
next
;
char
lenstr
[
128
];
size_t
lenstr_len
=
sprintf
(
lenstr
,
"
*
%ld
\r\n
"
,
length
);
size_t
lenstr_len
=
sprintf
(
lenstr
,
"
%c
%ld
\r\n
"
,
prefix
,
length
);
/* Abort when *node is NULL: when the client should not accept writes
* we return NULL in addDeferred
MultiBulkLength
() */
* we return NULL in add
Reply
Deferred
Len
() */
if
(
node
==
NULL
)
return
;
serverAssert
(
!
listNodeValue
(
ln
));
/* Normally we fill this dummy NULL node, added by addDeferred
MultiBulkLength
(),
/* Normally we fill this dummy NULL node, added by add
Reply
Deferred
Len
(),
* with a new buffer structure containing the protocol needed to specify
* the length of the array following. However sometimes when there is
* little memory to move, we may instead remove this NULL node, and prefix
...
...
@@ -467,6 +467,30 @@ void setDeferredMultiBulkLength(client *c, void *node, long length) {
asyncCloseClientOnOutputBufferLimitReached
(
c
);
}
void
setDeferredArrayLen
(
client
*
c
,
void
*
node
,
long
length
)
{
setDeferredAggregateLen
(
c
,
node
,
length
,
'*'
);
}
void
setDeferredMapLen
(
client
*
c
,
void
*
node
,
long
length
)
{
setDeferredAggregateLen
(
c
,
node
,
length
,
'%'
);
}
void
setDeferredSetLen
(
client
*
c
,
void
*
node
,
long
length
)
{
setDeferredAggregateLen
(
c
,
node
,
length
,
'~'
);
}
void
setDeferredAttributeLen
(
client
*
c
,
void
*
node
,
long
length
)
{
setDeferredAggregateLen
(
c
,
node
,
length
,
'|'
);
}
void
setDeferredPushLen
(
client
*
c
,
void
*
node
,
long
length
)
{
setDeferredAggregateLen
(
c
,
node
,
length
,
'>'
);
}
void
setDeferredHelloLen
(
client
*
c
,
void
*
node
,
long
length
)
{
setDeferredAggregateLen
(
c
,
node
,
length
,
'@'
);
}
/* Add a double as a bulk reply */
void
addReplyDouble
(
client
*
c
,
double
d
)
{
if
(
isinf
(
d
))
{
...
...
@@ -627,7 +651,7 @@ void addReplyBulkLongLong(client *c, long long ll) {
* is terminated by NULL sentinel. */
void
addReplyHelp
(
client
*
c
,
const
char
**
help
)
{
sds
cmd
=
sdsnew
((
char
*
)
c
->
argv
[
0
]
->
ptr
);
void
*
blenp
=
addDeferred
MultiBulkLength
(
c
);
void
*
blenp
=
add
Reply
Deferred
Len
(
c
);
int
blen
=
0
;
sdstoupper
(
cmd
);
...
...
@@ -638,7 +662,7 @@ void addReplyHelp(client *c, const char **help) {
while
(
help
[
blen
])
addReplyStatus
(
c
,
help
[
blen
++
]);
blen
++
;
/* Account for the header line(s). */
setDeferred
MultiBulkLength
(
c
,
blenp
,
blen
);
setDeferred
ArrayLen
(
c
,
blenp
,
blen
);
}
/* Add a suggestive error reply.
...
...
src/server.h
View file @
57c5a766
...
...
@@ -1424,8 +1424,13 @@ void freeClient(client *c);
void
freeClientAsync
(
client
*
c
);
void
resetClient
(
client
*
c
);
void
sendReplyToClient
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
);
void
*
addDeferredMultiBulkLength
(
client
*
c
);
void
setDeferredMultiBulkLength
(
client
*
c
,
void
*
node
,
long
length
);
void
*
addReplyDeferredLen
(
client
*
c
);
void
setDeferredArrayLen
(
client
*
c
,
void
*
node
,
long
length
);
void
setDeferredMapLen
(
client
*
c
,
void
*
node
,
long
length
);
void
setDeferredSetLen
(
client
*
c
,
void
*
node
,
long
length
);
void
setDeferredAttributeLen
(
client
*
c
,
void
*
node
,
long
length
);
void
setDeferredPushLen
(
client
*
c
,
void
*
node
,
long
length
);
void
setDeferredHelloLen
(
client
*
c
,
void
*
node
,
long
length
);
void
processInputBuffer
(
client
*
c
);
void
processInputBufferAndReplicate
(
client
*
c
);
void
acceptHandler
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
);
...
...
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