MCPcopy Create free account
hub / github.com/F-Stack/f-stack / acceptCommonHandler

Function acceptCommonHandler

app/redis-6.2.6/src/networking.c:1051–1121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1049
1050#define MAX_ACCEPTS_PER_CALL 500
1051static void acceptCommonHandler(connection *conn, int flags, char *ip) {
1052 client *c;
1053 char conninfo[100];
1054 UNUSED(ip);
1055
1056 if (connGetState(conn) != CONN_STATE_ACCEPTING) {
1057 serverLog(LL_VERBOSE,
1058 "Accepted client connection in error state: %s (conn: %s)",
1059 connGetLastError(conn),
1060 connGetInfo(conn, conninfo, sizeof(conninfo)));
1061 connClose(conn);
1062 return;
1063 }
1064
1065 /* Limit the number of connections we take at the same time.
1066 *
1067 * Admission control will happen before a client is created and connAccept()
1068 * called, because we don't want to even start transport-level negotiation
1069 * if rejected. */
1070 if (listLength(server.clients) + getClusterConnectionsCount()
1071 >= server.maxclients)
1072 {
1073 char *err;
1074 if (server.cluster_enabled)
1075 err = "-ERR max number of clients + cluster "
1076 "connections reached\r\n";
1077 else
1078 err = "-ERR max number of clients reached\r\n";
1079
1080 /* That's a best effort error message, don't check write errors.
1081 * Note that for TLS connections, no handshake was done yet so nothing
1082 * is written and the connection will just drop. */
1083 if (connWrite(conn,err,strlen(err)) == -1) {
1084 /* Nothing to do, Just to avoid the warning... */
1085 }
1086 server.stat_rejected_conn++;
1087 connClose(conn);
1088 return;
1089 }
1090
1091 /* Create connection and client */
1092 if ((c = createClient(conn)) == NULL) {
1093 serverLog(LL_WARNING,
1094 "Error registering fd event for the new client: %s (conn: %s)",
1095 connGetLastError(conn),
1096 connGetInfo(conn, conninfo, sizeof(conninfo)));
1097 connClose(conn); /* May be already closed, just ignore errors */
1098 return;
1099 }
1100
1101 /* Last chance to keep flags */
1102 c->flags |= flags;
1103
1104 /* Initiate accept.
1105 *
1106 * Note that connAccept() is free to do two things here:
1107 * 1. Call clientAcceptHandler() immediately;
1108 * 2. Schedule a future call to clientAcceptHandler().

Callers 3

acceptTcpHandlerFunction · 0.85
acceptTLSHandlerFunction · 0.85
acceptUnixHandlerFunction · 0.85

Calls 10

connGetStateFunction · 0.85
connGetLastErrorFunction · 0.85
connGetInfoFunction · 0.85
connCloseFunction · 0.85
connWriteFunction · 0.85
connAcceptFunction · 0.85
connGetPrivateDataFunction · 0.85
createClientFunction · 0.70
freeClientFunction · 0.70

Tested by

no test coverage detected