diff options
author | zhenwei pi <pizhenwei@bytedance.com> | 2022-08-22 15:15:37 +0800 |
---|---|---|
committer | zhenwei pi <pizhenwei@bytedance.com> | 2022-08-22 15:15:37 +0800 |
commit | 45617385e72eb814c6548064835cf19cdf466a5b (patch) | |
tree | 26bc3790c2e8626e4c3c74a5aa3c214a389c4d92 /src/tls.c | |
parent | eb94d6d36dec7323af5fb89a5899506d5c07adb1 (diff) | |
download | redis-45617385e72eb814c6548064835cf19cdf466a5b.tar.gz |
Use connection name of string
Suggested by Oran, use an array to store all the connection types
instead of a linked list, and use connection name of string. The index
of a connection is dynamically allocated.
Currently we support max 8 connection types, include:
- tcp
- unix socket
- tls
and RDMA is in the plan, then we have another 4 types to support, it
should be enough in a long time.
Introduce 3 functions to get connection type by a fast path:
- connectionTypeTcp()
- connectionTypeTls()
- connectionTypeUnix()
Note that connectionByType() is designed to use only in unlikely code path.
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/tls.c')
-rw-r--r-- | src/tls.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -763,7 +763,7 @@ static void connTLSClose(connection *conn_) { conn->pending_list_node = NULL; } - connectionByType(CONN_TYPE_SOCKET)->close(conn_); + connectionTypeTcp()->close(conn_); } static int connTLSAccept(connection *_conn, ConnectionCallbackFunc accept_handler) { @@ -802,7 +802,7 @@ static int connTLSConnect(connection *conn_, const char *addr, int port, const c ERR_clear_error(); /* Initiate Socket connection first */ - if (connectionByType(CONN_TYPE_SOCKET)->connect(conn_, addr, port, src_addr, connect_handler) == C_ERR) return C_ERR; + if (connectionTypeTcp()->connect(conn_, addr, port, src_addr, connect_handler) == C_ERR) return C_ERR; /* Return now, once the socket is connected we'll initiate * TLS connection from the event handler. @@ -965,7 +965,7 @@ static int connTLSBlockingConnect(connection *conn_, const char *addr, int port, if (conn->c.state != CONN_STATE_NONE) return C_ERR; /* Initiate socket blocking connect first */ - if (connectionByType(CONN_TYPE_SOCKET)->blocking_connect(conn_, addr, port, timeout) == C_ERR) return C_ERR; + if (connectionTypeTcp()->blocking_connect(conn_, addr, port, timeout) == C_ERR) return C_ERR; /* Initiate TLS connection now. We set up a send/recv timeout on the socket, * which means the specified timeout will not be enforced accurately. */ @@ -1034,7 +1034,7 @@ exit: return nread; } -static int connTLSGetType(connection *conn_) { +static const char *connTLSGetType(connection *conn_) { (void) conn_; return CONN_TYPE_TLS; @@ -1064,7 +1064,7 @@ static int tlsProcessPendingData() { */ static sds connTLSGetPeerCert(connection *conn_) { tls_connection *conn = (tls_connection *) conn_; - if (conn_->type->get_type(conn_) != CONN_TYPE_TLS || !conn->ssl) return NULL; + if ((conn_->type != connectionTypeTls()) || !conn->ssl) return NULL; X509 *cert = SSL_get_peer_certificate(conn->ssl); if (!cert) return NULL; |