summaryrefslogtreecommitdiff
path: root/src/connection.h
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/connection.h
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/connection.h')
-rw-r--r--src/connection.h12
1 files changed, 12 insertions, 0 deletions
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 <string.h>
#include <sys/uio.h>
+#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();