From 0ae02ce95b8a27ce9d19340e53dcdc9b5a060101 Mon Sep 17 00:00:00 2001 From: zhenwei pi Date: Wed, 27 Jul 2022 11:47:50 +0800 Subject: 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 --- src/connection.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/connection.h') diff --git a/src/connection.h b/src/connection.h index 4fca50fd1..feb084629 100644 --- a/src/connection.h +++ b/src/connection.h @@ -36,8 +36,11 @@ #include #include +#include "ae.h" + #define CONN_INFO_LEN 32 #define CONN_ADDR_STR_LEN 128 /* Similar to INET6_ADDRSTRLEN, hoping to handle other protocols. */ +#define MAX_ACCEPTS_PER_CALL 1000 struct aeEventLoop; typedef struct connection connection; @@ -71,6 +74,7 @@ typedef struct ConnectionType { /* ae & accept & listen & error & address handler */ void (*ae_handler)(struct aeEventLoop *el, int fd, void *clientData, int mask); + aeFileProc *accept_handler; int (*addr)(connection *conn, char *ip, size_t ip_len, int *port, int remote); /* create/close connection */ @@ -381,6 +385,14 @@ int connTypeHasPendingData(void); /* walk all the connection types and process pending data for each connection type */ int connTypeProcessPendingData(void); +/* Get accept_handler of a connection type */ +static inline aeFileProc *connAcceptHandler(int type) { + ConnectionType *ct = connectionByType(type); + if (ct) + return ct->accept_handler; + return NULL; +} + int RedisRegisterConnectionTypeSocket(); int RedisRegisterConnectionTypeTLS(); -- cgit v1.2.1