summaryrefslogtreecommitdiff
path: root/src/socket.c
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2022-07-27 10:46:31 +0800
committerzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:11:44 +0800
commit1234e3a5628260658adfe9065cb58ec5c1cb5ebe (patch)
tree98275a38f8d2938d7438c422371c758f28645d9a /src/socket.c
parentc4c02f80365e5f7a82efa6a4d4f247503f54a5d8 (diff)
downloadredis-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/socket.c')
-rw-r--r--src/socket.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/socket.c b/src/socket.c
index ce293e444..5aea1954e 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -49,7 +49,7 @@
* depending on the implementation (for TCP they are; for TLS they aren't).
*/
-ConnectionType CT_Socket;
+static ConnectionType CT_Socket;
/* When a connection is created we must know its type already, but the
* underlying socket may or may not exist:
@@ -74,7 +74,7 @@ ConnectionType CT_Socket;
* be embedded in different structs, not just client.
*/
-connection *connCreateSocket() {
+static connection *connCreateSocket(void) {
connection *conn = zcalloc(sizeof(connection));
conn->type = &CT_Socket;
conn->fd = -1;
@@ -92,7 +92,8 @@ connection *connCreateSocket() {
* is not in an error state (which is not possible for a socket connection,
* but could but possible with other protocols).
*/
-connection *connCreateAcceptedSocket(int fd) {
+static connection *connCreateAcceptedSocket(int fd, void *priv) {
+ UNUSED(priv);
connection *conn = connCreateSocket();
conn->fd = fd;
conn->state = CONN_STATE_ACCEPTING;
@@ -348,7 +349,7 @@ static int connSocketGetType(connection *conn) {
return CONN_TYPE_SOCKET;
}
-ConnectionType CT_Socket = {
+static ConnectionType CT_Socket = {
/* connection type */
.get_type = connSocketGetType,
@@ -362,6 +363,8 @@ ConnectionType CT_Socket = {
.addr = connSocketAddr,
/* create/close connection */
+ .conn_create = connCreateSocket,
+ .conn_create_accepted = connCreateAcceptedSocket,
.close = connSocketClose,
/* connect & accept */