diff -dru pgpool-II-2.0-beta1/main.c pgpool-II-2.0-beta1.fjo/main.c --- pgpool-II-2.0-beta1/main.c 2007-10-17 12:23:43.000000000 +0200 +++ pgpool-II-2.0-beta1.fjo/main.c 2007-11-07 09:59:51.000000000 +0100 @@ -93,6 +93,7 @@ static int pool_pause(struct timeval *timeout); static void pool_sleep(unsigned int second); static void kill_all_children(int sig); +static int drop_pending_connections(void); static RETSIGTYPE exit_handler(int sig); static RETSIGTYPE reap_handler(int sig); @@ -368,6 +369,10 @@ { inet_fd = create_inet_domain_socket(pool_config->listen_addresses, pool_config->port); } + else + { + inet_fd = -1; + } size = pool_config->num_init_children * pool_config->max_pool * sizeof(ConnectionInfo); con_info = pool_shared_memory_create(size); @@ -458,6 +463,8 @@ { CHECK_REQUEST; + drop_pending_connections(); + /* do we need health checking for PostgreSQL? */ if (pool_config->health_check_period > 0) { @@ -1756,3 +1763,48 @@ return r; } + +static int drop_pending_connections(void) +{ + struct timeval tv; + fd_set afds; + int status, new_conn; + struct sockaddr_in sin; + socklen_t sin_len; + + /* no inet socket */ + if (inet_fd == -1) + return 0; + + while (Req_info->conn_counter >= pool_config->num_init_children) { + /* check inet socket for pending connection */ + FD_ZERO(&afds); + FD_SET(inet_fd, &afds); + + tv.tv_sec = 0; + tv.tv_usec = 0; + + status = select(inet_fd + 1, &afds, NULL, NULL, &tv); + if (status < 0) + return -1; + if (status == 0) + break; + + /* accept connection and close it immediately */ + sin_len = sizeof(struct sockaddr_in); + new_conn = accept(inet_fd, &sin, &sin_len); + + if (new_conn < 0) + return -1; + + if (shutdown(new_conn, SHUT_RDWR) < 0) + return -1; + + pool_log("drop_pending_connections: %i current connections >= " + "num_init_children %i", + Req_info->conn_counter, + pool_config->num_init_children); + } + + return 0; +}