From 1234e3a5628260658adfe9065cb58ec5c1cb5ebe Mon Sep 17 00:00:00 2001 From: zhenwei pi Date: Wed, 27 Jul 2022 10:46:31 +0800 Subject: 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 --- src/replication.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/replication.c') diff --git a/src/replication.c b/src/replication.c index 3ae130252..8de14c9f2 100644 --- a/src/replication.c +++ b/src/replication.c @@ -55,6 +55,13 @@ int cancelReplicationHandshake(int reconnect); int RDBGeneratedByReplication = 0; /* --------------------------- Utility functions ---------------------------- */ +static int connTypeOfReplication() { + if (server.tls_replication) { + return CONN_TYPE_TLS; + } + + return CONN_TYPE_SOCKET; +} /* Return the pointer to a string representing the slave ip:listening_port * pair. Mostly useful for logging, since we want to log a slave using its @@ -2864,7 +2871,7 @@ write_error: /* Handle sendCommand() errors. */ } int connectWithMaster(void) { - server.repl_transfer_s = server.tls_replication ? connCreateTLS() : connCreateSocket(); + server.repl_transfer_s = connCreate(connTypeOfReplication()); if (connConnect(server.repl_transfer_s, server.masterhost, server.masterport, server.bind_source_addr, syncWithMaster) == C_ERR) { serverLog(LL_WARNING,"Unable to connect to MASTER: %s", -- cgit v1.2.1