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
0b01578d
Commit
0b01578d
authored
Apr 06, 2011
by
antirez
Browse files
Merge branch '2.2' of github.com:antirez/redis into 2.2
parents
920c45b8
fb90934c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
0b01578d
...
@@ -60,9 +60,6 @@ redisClient *createClient(int fd) {
...
@@ -60,9 +60,6 @@ redisClient *createClient(int fd) {
/* Set the event loop to listen for write events on the client's socket.
/* Set the event loop to listen for write events on the client's socket.
* Typically gets called every time a reply is built. */
* Typically gets called every time a reply is built. */
int
_installWriteEvent
(
redisClient
*
c
)
{
int
_installWriteEvent
(
redisClient
*
c
)
{
/* When CLOSE_AFTER_REPLY is set, no more replies may be added! */
redisAssert
(
!
(
c
->
flags
&
REDIS_CLOSE_AFTER_REPLY
));
if
(
c
->
fd
<=
0
)
return
REDIS_ERR
;
if
(
c
->
fd
<=
0
)
return
REDIS_ERR
;
if
(
c
->
bufpos
==
0
&&
listLength
(
c
->
reply
)
==
0
&&
if
(
c
->
bufpos
==
0
&&
listLength
(
c
->
reply
)
==
0
&&
(
c
->
replstate
==
REDIS_REPL_NONE
||
(
c
->
replstate
==
REDIS_REPL_NONE
||
...
@@ -88,9 +85,15 @@ robj *dupLastObjectIfNeeded(list *reply) {
...
@@ -88,9 +85,15 @@ robj *dupLastObjectIfNeeded(list *reply) {
return
listNodeValue
(
ln
);
return
listNodeValue
(
ln
);
}
}
/* -----------------------------------------------------------------------------
* Low level functions to add more data to output buffers.
* -------------------------------------------------------------------------- */
int
_addReplyToBuffer
(
redisClient
*
c
,
char
*
s
,
size_t
len
)
{
int
_addReplyToBuffer
(
redisClient
*
c
,
char
*
s
,
size_t
len
)
{
size_t
available
=
sizeof
(
c
->
buf
)
-
c
->
bufpos
;
size_t
available
=
sizeof
(
c
->
buf
)
-
c
->
bufpos
;
if
(
c
->
flags
&
REDIS_CLOSE_AFTER_REPLY
)
return
REDIS_OK
;
/* If there already are entries in the reply list, we cannot
/* If there already are entries in the reply list, we cannot
* add anything more to the static buffer. */
* add anything more to the static buffer. */
if
(
listLength
(
c
->
reply
)
>
0
)
return
REDIS_ERR
;
if
(
listLength
(
c
->
reply
)
>
0
)
return
REDIS_ERR
;
...
@@ -105,6 +108,9 @@ int _addReplyToBuffer(redisClient *c, char *s, size_t len) {
...
@@ -105,6 +108,9 @@ int _addReplyToBuffer(redisClient *c, char *s, size_t len) {
void
_addReplyObjectToList
(
redisClient
*
c
,
robj
*
o
)
{
void
_addReplyObjectToList
(
redisClient
*
c
,
robj
*
o
)
{
robj
*
tail
;
robj
*
tail
;
if
(
c
->
flags
&
REDIS_CLOSE_AFTER_REPLY
)
return
;
if
(
listLength
(
c
->
reply
)
==
0
)
{
if
(
listLength
(
c
->
reply
)
==
0
)
{
incrRefCount
(
o
);
incrRefCount
(
o
);
listAddNodeTail
(
c
->
reply
,
o
);
listAddNodeTail
(
c
->
reply
,
o
);
...
@@ -128,6 +134,12 @@ void _addReplyObjectToList(redisClient *c, robj *o) {
...
@@ -128,6 +134,12 @@ void _addReplyObjectToList(redisClient *c, robj *o) {
* needed it will be free'd, otherwise it ends up in a robj. */
* needed it will be free'd, otherwise it ends up in a robj. */
void
_addReplySdsToList
(
redisClient
*
c
,
sds
s
)
{
void
_addReplySdsToList
(
redisClient
*
c
,
sds
s
)
{
robj
*
tail
;
robj
*
tail
;
if
(
c
->
flags
&
REDIS_CLOSE_AFTER_REPLY
)
{
sdsfree
(
s
);
return
;
}
if
(
listLength
(
c
->
reply
)
==
0
)
{
if
(
listLength
(
c
->
reply
)
==
0
)
{
listAddNodeTail
(
c
->
reply
,
createObject
(
REDIS_STRING
,
s
));
listAddNodeTail
(
c
->
reply
,
createObject
(
REDIS_STRING
,
s
));
}
else
{
}
else
{
...
@@ -148,6 +160,9 @@ void _addReplySdsToList(redisClient *c, sds s) {
...
@@ -148,6 +160,9 @@ void _addReplySdsToList(redisClient *c, sds s) {
void
_addReplyStringToList
(
redisClient
*
c
,
char
*
s
,
size_t
len
)
{
void
_addReplyStringToList
(
redisClient
*
c
,
char
*
s
,
size_t
len
)
{
robj
*
tail
;
robj
*
tail
;
if
(
c
->
flags
&
REDIS_CLOSE_AFTER_REPLY
)
return
;
if
(
listLength
(
c
->
reply
)
==
0
)
{
if
(
listLength
(
c
->
reply
)
==
0
)
{
listAddNodeTail
(
c
->
reply
,
createStringObject
(
s
,
len
));
listAddNodeTail
(
c
->
reply
,
createStringObject
(
s
,
len
));
}
else
{
}
else
{
...
@@ -165,6 +180,11 @@ void _addReplyStringToList(redisClient *c, char *s, size_t len) {
...
@@ -165,6 +180,11 @@ void _addReplyStringToList(redisClient *c, char *s, size_t len) {
}
}
}
}
/* -----------------------------------------------------------------------------
* Higher level functions to queue data on the client output buffer.
* The following functions are the ones that commands implementations will call.
* -------------------------------------------------------------------------- */
void
addReply
(
redisClient
*
c
,
robj
*
obj
)
{
void
addReply
(
redisClient
*
c
,
robj
*
obj
)
{
if
(
_installWriteEvent
(
c
)
!=
REDIS_OK
)
return
;
if
(
_installWriteEvent
(
c
)
!=
REDIS_OK
)
return
;
redisAssert
(
!
server
.
vm_enabled
||
obj
->
storage
==
REDIS_VM_MEMORY
);
redisAssert
(
!
server
.
vm_enabled
||
obj
->
storage
==
REDIS_VM_MEMORY
);
...
...
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