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
d0001fe8
Commit
d0001fe8
authored
Jul 09, 2013
by
antirez
Browse files
getClientPeerId() refactored into two functions.
parent
e4c019e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
d0001fe8
...
@@ -1126,6 +1126,17 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
...
@@ -1126,6 +1126,17 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
*
biggest_input_buffer
=
bib
;
*
biggest_input_buffer
=
bib
;
}
}
/* This is an helper function for getClientPeerId().
* It writes the specified ip/port to "peerid" as a null termiated string
* in the form ip:port if ip does not contain ":" itself, otherwise
* [ip]:port format is used (for IPv6 addresses basically). */
void
formatPeerId
(
char
*
peerid
,
size_t
peerid_len
,
char
*
ip
,
int
port
)
{
if
(
strchr
(
ip
,
':'
))
snprintf
(
peerid
,
peerid_len
,
"[%s]:%d"
,
ip
,
port
);
else
snprintf
(
peerid
,
peerid_len
,
"%s:%d"
,
ip
,
port
);
}
/* A Redis "Peer ID" is a colon separated ip:port pair.
/* A Redis "Peer ID" is a colon separated ip:port pair.
* For IPv4 it's in the form x.y.z.k:pork, example: "127.0.0.1:1234".
* For IPv4 it's in the form x.y.z.k:pork, example: "127.0.0.1:1234".
* For IPv6 addresses we use [] around the IP part, like in "[::1]:1234".
* For IPv6 addresses we use [] around the IP part, like in "[::1]:1234".
...
@@ -1150,10 +1161,7 @@ int getClientPeerId(redisClient *client, char *peerid, size_t peerid_len) {
...
@@ -1150,10 +1161,7 @@ int getClientPeerId(redisClient *client, char *peerid, size_t peerid_len) {
}
else
{
}
else
{
/* TCP client. */
/* TCP client. */
int
retval
=
anetPeerToString
(
client
->
fd
,
ip
,
sizeof
(
ip
),
&
port
);
int
retval
=
anetPeerToString
(
client
->
fd
,
ip
,
sizeof
(
ip
),
&
port
);
if
(
strchr
(
ip
,
':'
))
formatPeerId
(
peerid
,
peerid_len
,
ip
,
port
);
snprintf
(
peerid
,
peerid_len
,
"[%s]:%d"
,
ip
,
port
);
else
snprintf
(
peerid
,
peerid_len
,
"%s:%d"
,
ip
,
port
);
return
(
retval
==
-
1
)
?
REDIS_ERR
:
REDIS_OK
;
return
(
retval
==
-
1
)
?
REDIS_ERR
:
REDIS_OK
;
}
}
}
}
...
...
src/redis.h
View file @
d0001fe8
...
@@ -1073,6 +1073,7 @@ void copyClientOutputBuffer(redisClient *dst, redisClient *src);
...
@@ -1073,6 +1073,7 @@ void copyClientOutputBuffer(redisClient *dst, redisClient *src);
void
*
dupClientReplyValue
(
void
*
o
);
void
*
dupClientReplyValue
(
void
*
o
);
void
getClientsMaxBuffers
(
unsigned
long
*
longest_output_list
,
void
getClientsMaxBuffers
(
unsigned
long
*
longest_output_list
,
unsigned
long
*
biggest_input_buffer
);
unsigned
long
*
biggest_input_buffer
);
void
formatPeerId
(
char
*
peerid
,
size_t
peerid_len
,
char
*
ip
,
int
port
);
int
getClientPeerId
(
redisClient
*
client
,
char
*
peerid
,
size_t
peerid_len
);
int
getClientPeerId
(
redisClient
*
client
,
char
*
peerid
,
size_t
peerid_len
);
sds
getClientInfoString
(
redisClient
*
client
);
sds
getClientInfoString
(
redisClient
*
client
);
sds
getAllClientsInfoString
(
void
);
sds
getAllClientsInfoString
(
void
);
...
...
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