| 713 | |
| 714 | #define MAX_CLUSTER_ACCEPTS_PER_CALL 1000 |
| 715 | void clusterAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) { |
| 716 | int cport, cfd; |
| 717 | int max = MAX_CLUSTER_ACCEPTS_PER_CALL; |
| 718 | char cip[NET_IP_STR_LEN]; |
| 719 | UNUSED(el); |
| 720 | UNUSED(mask); |
| 721 | UNUSED(privdata); |
| 722 | |
| 723 | /* If the server is starting up, don't accept cluster connections: |
| 724 | * UPDATE messages may interact with the database content. */ |
| 725 | if (listLength(g_pserver->masters) == 0 && g_pserver->loading) return; |
| 726 | |
| 727 | while(max--) { |
| 728 | cfd = anetTcpAccept(serverTL->neterr, fd, cip, sizeof(cip), &cport); |
| 729 | if (cfd == ANET_ERR) { |
| 730 | if (errno != EWOULDBLOCK) |
| 731 | serverLog(LL_VERBOSE, |
| 732 | "Error accepting cluster node: %s", serverTL->neterr); |
| 733 | return; |
| 734 | } |
| 735 | |
| 736 | connection *conn = g_pserver->tls_cluster ? |
| 737 | connCreateAcceptedTLS(cfd, TLS_CLIENT_AUTH_YES) : connCreateAcceptedSocket(cfd); |
| 738 | |
| 739 | /* Make sure connection is not in an error state */ |
| 740 | if (connGetState(conn) != CONN_STATE_ACCEPTING) { |
| 741 | serverLog(LL_VERBOSE, |
| 742 | "Error creating an accepting connection for cluster node: %s", |
| 743 | connGetLastError(conn)); |
| 744 | connClose(conn); |
| 745 | return; |
| 746 | } |
| 747 | connNonBlock(conn); |
| 748 | connEnableTcpNoDelay(conn); |
| 749 | connKeepAlive(conn,g_pserver->cluster_node_timeout * 2); |
| 750 | |
| 751 | /* Use non-blocking I/O for cluster messages. */ |
| 752 | serverLog(LL_VERBOSE,"Accepting cluster node connection from %s:%d", cip, cport); |
| 753 | |
| 754 | /* Accept the connection now. connAccept() may call our handler directly |
| 755 | * or schedule it for later depending on connection implementation. |
| 756 | */ |
| 757 | if (connAccept(conn, clusterConnAcceptHandler) == C_ERR) { |
| 758 | if (connGetState(conn) == CONN_STATE_ERROR) |
| 759 | serverLog(LL_VERBOSE, |
| 760 | "Error accepting cluster node connection: %s", |
| 761 | connGetLastError(conn)); |
| 762 | connClose(conn); |
| 763 | return; |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | /* Return the approximated number of sockets we are using in order to |
| 769 | * take the cluster bus connections. */ |
nothing calls this directly
no test coverage detected