summaryrefslogtreecommitdiff
path: root/src/networking.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/networking.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/networking.c')
-rw-r--r--src/networking.c43
1 files changed, 1 insertions, 42 deletions
diff --git a/src/networking.c b/src/networking.c
index 45ff585e2..d71e30b71 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -1255,8 +1255,7 @@ void clientAcceptHandler(connection *conn) {
c);
}
-#define MAX_ACCEPTS_PER_CALL 1000
-static void acceptCommonHandler(connection *conn, int flags, char *ip) {
+void acceptCommonHandler(connection *conn, int flags, char *ip) {
client *c;
char conninfo[100];
UNUSED(ip);
@@ -1328,46 +1327,6 @@ static void acceptCommonHandler(connection *conn, int flags, char *ip) {
}
}
-void acceptTcpHandler(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(connCreateAccepted(CONN_TYPE_SOCKET, cfd, NULL),0,cip);
- }
-}
-
-void acceptTLSHandler(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(connCreateAccepted(CONN_TYPE_TLS, cfd, &server.tls_auth_clients),0,cip);
- }
-}
-
void acceptUnixHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
int cfd, max = MAX_ACCEPTS_PER_CALL;
UNUSED(el);