From bff7ecc7864716c14fbb399f19acaee364975b29 Mon Sep 17 00:00:00 2001 From: zhenwei pi Date: Wed, 27 Jul 2022 10:08:32 +0800 Subject: Introduce connAddr Originally, connPeerToString is designed to get the address info from socket only(for both TCP & TLS), and the API 'connPeerToString' is oriented to operate a FD like: int connPeerToString(connection *conn, char *ip, size_t ip_len, int *port) { return anetFdToString(conn ? conn->fd : -1, ip, ip_len, port, FD_TO_PEER_NAME); } Introduce connAddr and implement .addr method for socket and TLS, thus the API 'connAddr' and 'connFormatAddr' become oriented to a connection like: 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); } return -1; } Also remove 'FD_TO_PEER_NAME' & 'FD_TO_SOCK_NAME', use a boolean type 'remote' to get local/remote address of a connection. With these changes, it's possible to support the other connection types which does not use socket(Ex, RDMA). Thanks to Oran for suggestions! Signed-off-by: zhenwei pi --- src/tls.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/tls.c') diff --git a/src/tls.c b/src/tls.c index 019f5a9d8..442824dcd 100644 --- a/src/tls.c +++ b/src/tls.c @@ -718,6 +718,10 @@ static void tlsEventHandler(struct aeEventLoop *el, int fd, void *clientData, in tlsHandleEvent(conn, mask); } +static int connTLSAddr(connection *conn, char *ip, size_t ip_len, int *port, int remote) { + return anetFdToString(conn->fd, ip, ip_len, port, remote); +} + static void connTLSClose(connection *conn_) { tls_connection *conn = (tls_connection *) conn_; @@ -1064,6 +1068,7 @@ ConnectionType CT_TLS = { /* ae & accept & listen & error & address handler */ .ae_handler = tlsEventHandler, + .addr = connTLSAddr, /* create/close connection */ .close = connTLSClose, -- cgit v1.2.1