mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
AnetFormatIP(): renamed, commented, now sticks to IP:port format.
A few code style changes + consistent format: not nice for humans but better for parsers.
This commit is contained in:
parent
491881e13b
commit
ce269ad3c5
19
src/anet.c
19
src/anet.c
@ -589,20 +589,21 @@ error:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int anetFormatIP(char *fmt, size_t fmt_len, char *ip, int port) {
|
/* Format an IP,port pair into something easy to parse. If IP is IPv6
|
||||||
if (port >= 0)
|
* (matches for ":"), the ip is surrounded by []. IP and port are just
|
||||||
return snprintf(fmt,fmt_len,
|
* separated by colons. This the standard to display addresses within Redis. */
|
||||||
strchr(ip,':') ? "[%s]:%d" : "%s:%d", ip, port);
|
int anetFormatAddr(char *buf, size_t buf_len, char *ip, int port) {
|
||||||
else
|
return snprintf(buf,buf_len, strchr(ip,':') ?
|
||||||
return snprintf(fmt, fmt_len, strchr(ip,':') ? "[%s]" : "%s", ip);
|
"[%s]:%d" : "%s:%d", ip, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
int anetFormatPeer(int fd, char *fmt, size_t fmt_len) {
|
/* Like anetFormatAddr() but extract ip and port from the socket's peer. */
|
||||||
|
int anetFormatPeer(int fd, char *buf, size_t buf_len) {
|
||||||
char ip[INET6_ADDRSTRLEN];
|
char ip[INET6_ADDRSTRLEN];
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
anetPeerToString(fd,ip,sizeof(ip),&port);
|
anetPeerToString(fd,ip,sizeof(ip),&port);
|
||||||
return anetFormatIP(fmt, fmt_len, ip, port);
|
return anetFormatAddr(buf, buf_len, ip, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
int anetSockName(int fd, char *ip, size_t ip_len, int *port) {
|
int anetSockName(int fd, char *ip, size_t ip_len, int *port) {
|
||||||
@ -632,5 +633,5 @@ int anetFormatSock(int fd, char *fmt, size_t fmt_len) {
|
|||||||
int port;
|
int port;
|
||||||
|
|
||||||
anetSockName(fd,ip,sizeof(ip),&port);
|
anetSockName(fd,ip,sizeof(ip),&port);
|
||||||
return anetFormatIP(fmt, fmt_len, ip, port);
|
return anetFormatAddr(fmt, fmt_len, ip, port);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ int anetSendTimeout(char *err, int fd, long long ms);
|
|||||||
int anetPeerToString(int fd, char *ip, size_t ip_len, int *port);
|
int anetPeerToString(int fd, char *ip, size_t ip_len, int *port);
|
||||||
int anetKeepAlive(char *err, int fd, int interval);
|
int anetKeepAlive(char *err, int fd, int interval);
|
||||||
int anetSockName(int fd, char *ip, size_t ip_len, int *port);
|
int anetSockName(int fd, char *ip, size_t ip_len, int *port);
|
||||||
int anetFormatIP(char *fmt, size_t fmt_len, char *ip, int port);
|
int anetFormatAddr(char *fmt, size_t fmt_len, char *ip, int port);
|
||||||
int anetFormatPeer(int fd, char *fmt, size_t fmt_len);
|
int anetFormatPeer(int fd, char *fmt, size_t fmt_len);
|
||||||
int anetFormatSock(int fd, char *fmt, size_t fmt_len);
|
int anetFormatSock(int fd, char *fmt, size_t fmt_len);
|
||||||
|
|
||||||
|
@ -1553,7 +1553,7 @@ int clusterProcessPacket(clusterLink *link) {
|
|||||||
{
|
{
|
||||||
memcpy(myself->ip,ip,REDIS_IP_STR_LEN);
|
memcpy(myself->ip,ip,REDIS_IP_STR_LEN);
|
||||||
|
|
||||||
anetFormatIP(ip, sizeof(ip), myself->ip, -1);
|
anetFormatAddr(ip, sizeof(ip), myself->ip, -1);
|
||||||
redisLog(REDIS_WARNING,"IP address for this node updated to %s",
|
redisLog(REDIS_WARNING,"IP address for this node updated to %s",
|
||||||
ip);
|
ip);
|
||||||
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG);
|
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG);
|
||||||
|
@ -130,7 +130,7 @@ static void cliRefreshPrompt(void) {
|
|||||||
len = snprintf(config.prompt,sizeof(config.prompt),"redis %s",
|
len = snprintf(config.prompt,sizeof(config.prompt),"redis %s",
|
||||||
config.hostsocket);
|
config.hostsocket);
|
||||||
else
|
else
|
||||||
len = anetFormatIP(config.prompt, sizeof(config.prompt),
|
len = anetFormatAddr(config.prompt, sizeof(config.prompt),
|
||||||
config.hostip, config.hostport);
|
config.hostip, config.hostport);
|
||||||
/* Add [dbnum] if needed */
|
/* Add [dbnum] if needed */
|
||||||
if (config.dbnum != 0 && config.last_cmd_type != REDIS_REPLY_ERROR)
|
if (config.dbnum != 0 && config.last_cmd_type != REDIS_REPLY_ERROR)
|
||||||
|
@ -56,7 +56,7 @@ char *replicationGetSlaveName(redisClient *c) {
|
|||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
if (anetPeerToString(c->fd,ip,sizeof(ip),NULL) != -1) {
|
if (anetPeerToString(c->fd,ip,sizeof(ip),NULL) != -1) {
|
||||||
if (c->slave_listening_port)
|
if (c->slave_listening_port)
|
||||||
anetFormatIP(buf,sizeof(buf),ip,c->slave_listening_port);
|
anetFormatAddr(buf,sizeof(buf),ip,c->slave_listening_port);
|
||||||
else
|
else
|
||||||
snprintf(buf,sizeof(buf),"%s:<unknown-slave-port>",ip);
|
snprintf(buf,sizeof(buf),"%s:<unknown-slave-port>",ip);
|
||||||
} else {
|
} else {
|
||||||
|
@ -908,7 +908,7 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char *
|
|||||||
|
|
||||||
/* For slaves and sentinel we use ip:port as name. */
|
/* For slaves and sentinel we use ip:port as name. */
|
||||||
if (flags & (SRI_SLAVE|SRI_SENTINEL)) {
|
if (flags & (SRI_SLAVE|SRI_SENTINEL)) {
|
||||||
anetFormatIP(slavename, sizeof(slavename), hostname, port);
|
anetFormatAddr(slavename, sizeof(slavename), hostname, port);
|
||||||
name = slavename;
|
name = slavename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user