diff --git a/src/connection.c b/src/connection.c index edb2c4994..5a5cd2767 100644 --- a/src/connection.c +++ b/src/connection.c @@ -183,3 +183,22 @@ int connTypeProcessPendingData(void) { return ret; } +sds getListensInfoString(sds info) { + for (int j = 0; j < CONN_TYPE_MAX; j++) { + connListener *listener = &server.listeners[j]; + if (listener->ct == NULL) + continue; + + info = sdscatfmt(info, "listener%i:name=%s", j, listener->ct->get_type(NULL)); + for (int i = 0; i < listener->count; i++) { + info = sdscatfmt(info, ",bind=%s", listener->bindaddr[i]); + } + + if (listener->port) + info = sdscatfmt(info, ",port=%i", listener->port); + + info = sdscatfmt(info, "\r\n"); + } + + return info; +} diff --git a/src/connection.h b/src/connection.h index ab68b6975..9fe5277e5 100644 --- a/src/connection.h +++ b/src/connection.h @@ -275,7 +275,7 @@ static inline int connLastErrorRetryable(connection *conn) { } /* Get address information of a connection. - * @remote works as boolean type to get local/remote address */ + * remote works as boolean type to get local/remote address */ static inline int connAddr(connection *conn, char *ip, size_t ip_len, int *port, int remote) { if (conn && conn->type->addr) { return conn->type->addr(conn, ip, ip_len, port, remote); @@ -287,8 +287,8 @@ static inline int connAddr(connection *conn, char *ip, size_t ip_len, int *port, /* Format an IP,port pair into something easy to parse. If IP is IPv6 * (matches for ":"), the ip is surrounded by []. IP and port are just * separated by colons. This the standard to display addresses within Redis. */ -static inline int formatAddr(char *buf, size_t buf_len, char *ip, int port) { - return snprintf(buf,buf_len, strchr(ip,':') ? +static inline int formatAddr(char *buf, size_t buf_len, char *ip, int port) { + return snprintf(buf, buf_len, strchr(ip,':') ? "[%s]:%d" : "%s:%d", ip, port); } @@ -400,19 +400,19 @@ static inline connection *connCreate(ConnectionType *ct) { } /* Create a accepted connection of specified type. - * @priv is connection type specified argument */ + * priv is connection type specified argument */ static inline connection *connCreateAccepted(ConnectionType *ct, int fd, void *priv) { return ct->conn_create_accepted(fd, priv); } /* Configure a connection type. A typical case is to configure TLS. - * @priv is connection type specified, - * @reconfigure is boolean type to specify if overwrite the original config */ + * priv is connection type specified, + * reconfigure is boolean type to specify if overwrite the original config */ static inline int connTypeConfigure(ConnectionType *ct, void *priv, int reconfigure) { return ct->configure(priv, reconfigure); } -/* Walk all the connection type, and cleanup them all if possible */ +/* Walk all the connection types and cleanup them all if possible */ void connTypeCleanupAll(); /* Test all the connection type has pending data or not. */ @@ -433,6 +433,9 @@ static inline aeFileProc *connAcceptHandler(ConnectionType *ct) { return NULL; } +/* Get Listeners information, note that caller should free the non-empty string */ +sds getListensInfoString(sds info); + int RedisRegisterConnectionTypeSocket(); int RedisRegisterConnectionTypeUnix(); int RedisRegisterConnectionTypeTLS(); diff --git a/src/server.c b/src/server.c index 29397880d..f01805840 100644 --- a/src/server.c +++ b/src/server.c @@ -5426,6 +5426,9 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { "shutdown_in_milliseconds:%I\r\n", (int64_t)(server.shutdown_mstime - server.mstime)); } + + /* get all the listeners information */ + info = getListensInfoString(info); } /* Clients */