summaryrefslogtreecommitdiff
path: root/src/socket.c
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:09:59 +0800
committerzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:09:59 +0800
commit8234a5123d8727a0b72c7b1a2524edd113ffe016 (patch)
tree1418f61000d9be9a0c7d2d616be02b7cd346ae78 /src/socket.c
parentbff7ecc7864716c14fbb399f19acaee364975b29 (diff)
downloadredis-8234a5123d8727a0b72c7b1a2524edd113ffe016.tar.gz
Introduce connection layer framework
Use connTypeRegister() to register a connection type into redis, and query connection by connectionByType() via type. With this change, we can hide TLS specified methods into connection type: - void tlsInit(void); - void tlsCleanup(void); - int tlsConfigure(redisTLSContextConfig *ctx_config); - int isTlsConfigured(void); Merge isTlsConfigured & tlsConfigure, use an argument *reconfigure* to distinguish: tlsConfigure(&server.tls_ctx_config) -> onnTypeConfigure(CONN_TYPE_TLS, &server.tls_ctx_config, 1) isTlsConfigured() && tlsConfigure(&server.tls_ctx_config) -> connTypeConfigure(CONN_TYPE_TLS, &server.tls_ctx_config, 0) Finally, we can remove USE_OPENSSL from config.c. If redis is built without TLS, and still run redis with TLS, then redis reports: # Missing implement of connection type 1 # Failed to configure TLS. Check logs for more info. The log can be optimised, let's leave it in the future. Maybe we can use connection type as a string. Although uninitialized fields of a static struct are zero, we still set them as NULL explicitly in socket.c, let them clear to read & maintain: .init = NULL, .cleanup = NULL, .configure = NULL, Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/socket.c')
-rw-r--r--src/socket.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/socket.c b/src/socket.c
index 2ef29e1d4..d93882cce 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -352,6 +352,11 @@ ConnectionType CT_Socket = {
/* connection type */
.get_type = connSocketGetType,
+ /* connection type initialize & finalize & configure */
+ .init = NULL,
+ .cleanup = NULL,
+ .configure = NULL,
+
/* ae & accept & listen & error & address handler */
.ae_handler = connSocketEventHandler,
.addr = connSocketAddr,
@@ -409,3 +414,7 @@ int connRecvTimeout(connection *conn, long long ms) {
return anetRecvTimeout(NULL, conn->fd, ms);
}
+int RedisRegisterConnectionTypeSocket()
+{
+ return connTypeRegister(&CT_Socket);
+}