mirror of
https://github.com/fluencelabs/redis
synced 2025-04-17 22:52:13 +00:00
anetPeerToString() automatically populates ip/port with something that may be provided to the user as output in case of errors.
This commit is contained in:
parent
9494f1f15b
commit
7b845b6228
@ -353,7 +353,12 @@ int anetPeerToString(int fd, char *ip, int *port) {
|
|||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
socklen_t salen = sizeof(sa);
|
socklen_t salen = sizeof(sa);
|
||||||
|
|
||||||
if (getpeername(fd,(struct sockaddr*)&sa,&salen) == -1) return -1;
|
if (getpeername(fd,(struct sockaddr*)&sa,&salen) == -1) {
|
||||||
|
*port = 0;
|
||||||
|
ip[0] = '?';
|
||||||
|
ip[1] = '\0';
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (ip) strcpy(ip,inet_ntoa(sa.sin_addr));
|
if (ip) strcpy(ip,inet_ntoa(sa.sin_addr));
|
||||||
if (port) *port = ntohs(sa.sin_port);
|
if (port) *port = ntohs(sa.sin_port);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1087,11 +1087,7 @@ sds getClientInfoString(redisClient *client) {
|
|||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
int emask;
|
int emask;
|
||||||
|
|
||||||
if (anetPeerToString(client->fd,ip,&port) == -1) {
|
anetPeerToString(client->fd,ip,&port);
|
||||||
ip[0] = '?';
|
|
||||||
ip[1] = '\0';
|
|
||||||
port = 0;
|
|
||||||
}
|
|
||||||
p = flags;
|
p = flags;
|
||||||
if (client->flags & REDIS_SLAVE) {
|
if (client->flags & REDIS_SLAVE) {
|
||||||
if (client->flags & REDIS_MONITOR)
|
if (client->flags & REDIS_MONITOR)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user