diff options
author | zhenwei pi <pizhenwei@bytedance.com> | 2022-07-27 10:08:32 +0800 |
---|---|---|
committer | zhenwei pi <pizhenwei@bytedance.com> | 2022-08-22 15:01:40 +0800 |
commit | bff7ecc7864716c14fbb399f19acaee364975b29 (patch) | |
tree | 7f342f044ee6e39769b55e1a1754abb4ffc39dac /src/anet.h | |
parent | b9d77288243aeab306b99ff72a71d8490a91e0a8 (diff) | |
download | redis-bff7ecc7864716c14fbb399f19acaee364975b29.tar.gz |
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 <pizhenwei@bytedance.com>
Diffstat (limited to 'src/anet.h')
-rw-r--r-- | src/anet.h | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/src/anet.h b/src/anet.h index b1a3847de..b571e52c1 100644 --- a/src/anet.h +++ b/src/anet.h @@ -49,10 +49,6 @@ #undef ip_len #endif -/* FD to address string conversion types */ -#define FD_TO_PEER_NAME 0 -#define FD_TO_SOCK_NAME 1 - int anetTcpNonBlockConnect(char *err, const char *addr, int port); int anetTcpNonBlockBestEffortBindConnect(char *err, const char *addr, int port, const char *source_addr); int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len, int flags); @@ -68,10 +64,9 @@ int anetEnableTcpNoDelay(char *err, int fd); int anetDisableTcpNoDelay(char *err, int fd); int anetSendTimeout(char *err, int fd, long long ms); int anetRecvTimeout(char *err, int fd, long long ms); -int anetFdToString(int fd, char *ip, size_t ip_len, int *port, int fd_to_str_type); +int anetFdToString(int fd, char *ip, size_t ip_len, int *port, int remote); int anetKeepAlive(char *err, int fd, int interval); int anetFormatAddr(char *fmt, size_t fmt_len, char *ip, int port); -int anetFormatFdAddr(int fd, char *buf, size_t buf_len, int fd_to_str_type); int anetPipe(int fds[2], int read_flags, int write_flags); int anetSetSockMarkId(char *err, int fd, uint32_t id); int anetGetError(int fd); |