summaryrefslogtreecommitdiff
path: root/src/tls.c
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2022-07-27 11:47:50 +0800
committerzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:12:18 +0800
commit0ae02ce95b8a27ce9d19340e53dcdc9b5a060101 (patch)
tree85e6f54508a87fbb74da0fab18697184ba8591e3 /src/tls.c
parent41fff55d527dc1987097da201cac009d1c7b9572 (diff)
downloadredis-0ae02ce95b8a27ce9d19340e53dcdc9b5a060101.tar.gz
Abstract accept handler
Abstract accept handler for socket&TLS, and add helper function 'connAcceptHandler' to get accept handler by specified type. Also move acceptTcpHandler into socket.c, and move acceptTLSHandler into tls.c. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/tls.c')
-rw-r--r--src/tls.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/tls.c b/src/tls.c
index 39108afed..c459ba8f2 100644
--- a/src/tls.c
+++ b/src/tls.c
@@ -719,6 +719,26 @@ static void tlsEventHandler(struct aeEventLoop *el, int fd, void *clientData, in
tlsHandleEvent(conn, mask);
}
+static void tlsAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
+ int cport, cfd, max = MAX_ACCEPTS_PER_CALL;
+ char cip[NET_IP_STR_LEN];
+ UNUSED(el);
+ UNUSED(mask);
+ UNUSED(privdata);
+
+ while(max--) {
+ cfd = anetTcpAccept(server.neterr, fd, cip, sizeof(cip), &cport);
+ if (cfd == ANET_ERR) {
+ if (errno != EWOULDBLOCK)
+ serverLog(LL_WARNING,
+ "Accepting client connection: %s", server.neterr);
+ return;
+ }
+ serverLog(LL_VERBOSE,"Accepted %s:%d", cip, cport);
+ acceptCommonHandler(connCreateAcceptedTLS(cfd, &server.tls_auth_clients),0,cip);
+ }
+}
+
static int connTLSAddr(connection *conn, char *ip, size_t ip_len, int *port, int remote) {
return anetFdToString(conn->fd, ip, ip_len, port, remote);
}
@@ -1082,6 +1102,7 @@ static ConnectionType CT_TLS = {
/* ae & accept & listen & error & address handler */
.ae_handler = tlsEventHandler,
+ .accept_handler = tlsAcceptHandler,
.addr = connTLSAddr,
/* create/close connection */