summaryrefslogtreecommitdiff
path: root/src/connection.h
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2023-01-04 16:52:56 +0800
committerGitHub <noreply@github.com>2023-01-04 10:52:56 +0200
commitdec529f4be3e3314300bb513e7a9f3af636e13b0 (patch)
treeaeca1a2a40c5da584fac4c220aaf85d4064ad6e4 /src/connection.h
parent884ca601b21ec6ef4d216ae850c0cf503f762623 (diff)
downloadredis-dec529f4be3e3314300bb513e7a9f3af636e13b0.tar.gz
Introduce .is_local method for connection layer (#11672)
Introduce .is_local method to connection, and implement for TCP/TLS/ Unix socket, also drop 'int islocalClient(client *c)'. Then we can hide the detail into the specific connection types. Uplayer tests a connection is local or not by abstract method only. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/connection.h')
-rw-r--r--src/connection.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/connection.h b/src/connection.h
index 62dc8d157..da8b1b7c7 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -78,6 +78,7 @@ typedef struct ConnectionType {
void (*ae_handler)(struct aeEventLoop *el, int fd, void *clientData, int mask);
aeFileProc *accept_handler;
int (*addr)(connection *conn, char *ip, size_t ip_len, int *port, int remote);
+ int (*is_local)(connection *conn);
int (*listen)(connListener *listener);
/* create/shutdown/close connection */
@@ -315,6 +316,16 @@ static inline int connAddrSockName(connection *conn, char *ip, size_t ip_len, in
return connAddr(conn, ip, ip_len, port, 0);
}
+/* Test a connection is local or loopback.
+ * Return -1 on failure, 0 is not a local connection, 1 is a local connection */
+static inline int connIsLocal(connection *conn) {
+ if (conn && conn->type->is_local) {
+ return conn->type->is_local(conn);
+ }
+
+ return -1;
+}
+
static inline int connGetState(connection *conn) {
return conn->state;
}