diff options
author | zhenwei pi <pizhenwei@bytedance.com> | 2022-07-27 10:46:31 +0800 |
---|---|---|
committer | zhenwei pi <pizhenwei@bytedance.com> | 2022-08-22 15:11:44 +0800 |
commit | 1234e3a5628260658adfe9065cb58ec5c1cb5ebe (patch) | |
tree | 98275a38f8d2938d7438c422371c758f28645d9a /src/connection.c | |
parent | c4c02f80365e5f7a82efa6a4d4f247503f54a5d8 (diff) | |
download | redis-1234e3a5628260658adfe9065cb58ec5c1cb5ebe.tar.gz |
Fully abstract connection type
Abstract common interface of connection type, so Redis can hide the
implementation and uplayer only calls connection API without macro.
uplayer
|
connection layer
/ \
socket TLS
Currently, for both socket and TLS, all the methods of connection type
are declared as static functions.
It's possible to build TLS(even socket) as a shared library, and Redis
loads it dynamically in the next step.
Also add helper function connTypeOfCluster() and
connTypeOfReplication() to simplify the code:
link->conn = server.tls_cluster ? connCreateTLS() : connCreateSocket();
-> link->conn = connCreate(connTypeOfCluster());
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/connection.c')
-rw-r--r-- | src/connection.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/connection.c b/src/connection.c index e28257fab..72db82212 100644 --- a/src/connection.c +++ b/src/connection.c @@ -152,3 +152,18 @@ void *connTypeGetClientCtx(int type) { return NULL; } +connection *connCreate(int type) { + ConnectionType *ct = connectionByType(type); + + serverAssert(ct && ct->conn_create); + + return ct->conn_create(); +} + +connection *connCreateAccepted(int type, int fd, void *priv) { + ConnectionType *ct = connectionByType(type); + + serverAssert(ct && ct->conn_create_accepted); + + return ct->conn_create_accepted(fd, priv); +} |