| 674 | |
| 675 | #define MAX_CLUSTER_ACCEPTS_PER_CALL 1000 |
| 676 | void clusterAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) { |
| 677 | int cport, cfd; |
| 678 | int max = MAX_CLUSTER_ACCEPTS_PER_CALL; |
| 679 | char cip[NET_IP_STR_LEN]; |
| 680 | UNUSED(el); |
| 681 | UNUSED(mask); |
| 682 | UNUSED(privdata); |
| 683 | |
| 684 | /* If the server is starting up, don't accept cluster connections: |
| 685 | * UPDATE messages may interact with the database content. */ |
| 686 | if (server.masterhost == NULL && server.loading) return; |
| 687 | |
| 688 | while(max--) { |
| 689 | cfd = anetTcpAccept(server.neterr, fd, cip, sizeof(cip), &cport); |
| 690 | if (cfd == ANET_ERR) { |
| 691 | if (errno != EWOULDBLOCK) |
| 692 | serverLog(LL_VERBOSE, |
| 693 | "Error accepting cluster node: %s", server.neterr); |
| 694 | return; |
| 695 | } |
| 696 | |
| 697 | connection *conn = server.tls_cluster ? |
| 698 | connCreateAcceptedTLS(cfd, TLS_CLIENT_AUTH_YES) : connCreateAcceptedSocket(cfd); |
| 699 | |
| 700 | /* Make sure connection is not in an error state */ |
| 701 | if (connGetState(conn) != CONN_STATE_ACCEPTING) { |
| 702 | serverLog(LL_VERBOSE, |
| 703 | "Error creating an accepting connection for cluster node: %s", |
| 704 | connGetLastError(conn)); |
| 705 | connClose(conn); |
| 706 | return; |
| 707 | } |
| 708 | connNonBlock(conn); |
| 709 | connEnableTcpNoDelay(conn); |
| 710 | connKeepAlive(conn,server.cluster_node_timeout * 2); |
| 711 | |
| 712 | /* Use non-blocking I/O for cluster messages. */ |
| 713 | serverLog(LL_VERBOSE,"Accepting cluster node connection from %s:%d", cip, cport); |
| 714 | |
| 715 | /* Accept the connection now. connAccept() may call our handler directly |
| 716 | * or schedule it for later depending on connection implementation. |
| 717 | */ |
| 718 | if (connAccept(conn, clusterConnAcceptHandler) == C_ERR) { |
| 719 | if (connGetState(conn) == CONN_STATE_ERROR) |
| 720 | serverLog(LL_VERBOSE, |
| 721 | "Error accepting cluster node connection: %s", |
| 722 | connGetLastError(conn)); |
| 723 | connClose(conn); |
| 724 | return; |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | /* Return the approximated number of sockets we are using in order to |
| 730 | * take the cluster bus connections. */ |
nothing calls this directly
no test coverage detected