@@ -337,8 +337,6 @@ static int cdb2_add_ssl_session(cdb2_hndl_tp *hndl);
337337
338338static pthread_mutex_t cdb2_cfg_lock = PTHREAD_MUTEX_INITIALIZER ;
339339
340- static void reset_sockpool (void );
341-
342340#ifdef CDB2API_TEST
343341#include "cdb2api_test.h"
344342#define MAKE_CDB2API_TEST_SWITCH (name ) \
@@ -2429,11 +2427,8 @@ static int get_comdb2db_hosts(cdb2_hndl_tp *hndl, char comdb2db_hosts[][CDB2HOST
24292427
24302428/* SOCKPOOL CODE START */
24312429
2432- #define SOCKPOOL_ENABLED_DEFAULT 1
2433- static int sockpool_enabled = SOCKPOOL_ENABLED_DEFAULT ;
2434-
2435- #define SOCKPOOL_FAIL_TIME_DEFAULT 0
2436- static time_t sockpool_fail_time = SOCKPOOL_FAIL_TIME_DEFAULT ;
2430+ static int sockpool_enabled = 1 ;
2431+ static time_t sockpool_fail_time = 0 ;
24372432
24382433struct sockpool_fd_list {
24392434 int sockpool_fd ;
@@ -2442,7 +2437,6 @@ struct sockpool_fd_list {
24422437
24432438static struct sockpool_fd_list * sockpool_fds = NULL ;
24442439static int sockpool_fd_count = 0 ;
2445- static int sockpool_generation = 0 ;
24462440
24472441struct sockaddr_sun {
24482442 short sun_family ;
@@ -2531,35 +2525,12 @@ void cdb2_enable_sockpool()
25312525 pthread_mutex_unlock (& cdb2_sockpool_mutex );
25322526}
25332527
2534- static void cdb2_maybe_disable_sockpool (int forceClose , int enabled )
2535- {
2536- pthread_mutex_lock (& cdb2_sockpool_mutex );
2537- /* Close sockpool fd */
2538- if (forceClose || (sockpool_enabled != -1 )) {
2539- sockpool_generation ++ ;
2540- for (int i = 0 ; i < sockpool_fd_count ; i ++ ) {
2541- struct sockpool_fd_list * sp = & sockpool_fds [i ];
2542- if (sp -> in_use == 0 ) {
2543- if (sp -> sockpool_fd > -1 )
2544- close (sp -> sockpool_fd );
2545- sp -> sockpool_fd = -1 ;
2546- }
2547- }
2548- }
2549- sockpool_enabled = enabled ;
2550- pthread_mutex_unlock (& cdb2_sockpool_mutex );
2551- }
2552-
25532528/* Disable sockpool and close sockpool socket */
25542529void cdb2_disable_sockpool ()
25552530{
2556- cdb2_maybe_disable_sockpool (0 , -1 );
2557- }
2558-
2559- static void reset_sockpool (void )
2560- {
2561- cdb2_maybe_disable_sockpool (1 , SOCKPOOL_ENABLED_DEFAULT );
2562- sockpool_fail_time = SOCKPOOL_FAIL_TIME_DEFAULT ;
2531+ pthread_mutex_lock (& cdb2_sockpool_mutex );
2532+ sockpool_enabled = -1 ;
2533+ pthread_mutex_unlock (& cdb2_sockpool_mutex );
25632534}
25642535
25652536/* The sockpool mutex must be locked at this point */
@@ -3047,7 +3018,6 @@ static
30473018// cdb2_socket_pool_get_ll: low-level
30483019static int cdb2_socket_pool_get_ll (cdb2_hndl_tp * hndl , const char * typestr , int dbnum , int * port )
30493020{
3050- int sp_generation = -1 ;
30513021 int fd = -1 ;
30523022
30533023#ifdef CDB2API_TEST
@@ -3077,7 +3047,6 @@ static int cdb2_socket_pool_get_ll(cdb2_hndl_tp *hndl, const char *typestr, int
30773047 }
30783048 enabled = sockpool_enabled ;
30793049 if (enabled == 1 ) {
3080- sp_generation = sockpool_generation ;
30813050 sockpool_fd = sockpool_get_from_pool ();
30823051 }
30833052 pthread_mutex_unlock (& cdb2_sockpool_mutex );
@@ -3097,18 +3066,11 @@ static int cdb2_socket_pool_get_ll(cdb2_hndl_tp *hndl, const char *typestr, int
30973066 struct sockpool_msg_vers0 msg = {0 };
30983067 int rc ;
30993068 if (strlen (typestr ) >= sizeof (msg .typestr )) {
3100- int closeit = 0 ;
3069+ int do_close ;
31013070 pthread_mutex_lock (& cdb2_sockpool_mutex );
3102- if (sp_generation == sockpool_generation ) {
3103- if ((sockpool_place_fd_in_pool (sockpool_fd )) != 0 ) {
3104- closeit = 1 ;
3105- }
3106- } else {
3107- sockpool_remove_fd (sockpool_fd );
3108- closeit = 1 ;
3109- }
3071+ do_close = sockpool_place_fd_in_pool (sockpool_fd );
31103072 pthread_mutex_unlock (& cdb2_sockpool_mutex );
3111- if (closeit )
3073+ if (do_close )
31123074 close (sockpool_fd );
31133075 return -1 ;
31143076 }
@@ -3152,18 +3114,11 @@ static int cdb2_socket_pool_get_ll(cdb2_hndl_tp *hndl, const char *typestr, int
31523114 }
31533115
31543116 if (sockpool_fd != -1 ) {
3155- int closeit = 0 ;
3117+ int do_close ;
31563118 pthread_mutex_lock (& cdb2_sockpool_mutex );
3157- if (sp_generation == sockpool_generation ) {
3158- if ((sockpool_place_fd_in_pool (sockpool_fd )) != 0 ) {
3159- closeit = 1 ;
3160- }
3161- } else {
3162- sockpool_remove_fd (sockpool_fd );
3163- closeit = 1 ;
3164- }
3119+ do_close = sockpool_place_fd_in_pool (sockpool_fd );
31653120 pthread_mutex_unlock (& cdb2_sockpool_mutex );
3166- if (closeit )
3121+ if (do_close )
31673122 close (sockpool_fd );
31683123 }
31693124
@@ -3251,18 +3206,15 @@ void cdb2_socket_pool_donate_ext(const cdb2_hndl_tp *hndl, const char *typestr,
32513206
32523207 int enabled = 0 ;
32533208 int sockpool_fd = -1 ;
3254- int sp_generation = -1 ;
32553209
32563210 pthread_mutex_lock (& cdb2_sockpool_mutex );
32573211 if (cdb2_use_env_vars ) {
32583212 enabled = (hndl && hndl -> sockpool_enabled == -1 ) ? -1 : sockpool_enabled ;
32593213 } else {
32603214 enabled = sockpool_enabled ;
32613215 }
3262- if (enabled == 1 ) {
3216+ if (enabled == 1 )
32633217 sockpool_fd = sockpool_get_from_pool ();
3264- sp_generation = sockpool_generation ;
3265- }
32663218 pthread_mutex_unlock (& cdb2_sockpool_mutex );
32673219
32683220 if (enabled == 1 ) {
@@ -3305,18 +3257,11 @@ void cdb2_socket_pool_donate_ext(const cdb2_hndl_tp *hndl, const char *typestr,
33053257 }
33063258
33073259 if (sockpool_fd != -1 ) {
3260+ int do_close ;
33083261 pthread_mutex_lock (& cdb2_sockpool_mutex );
3309- int closeit = 0 ;
3310- if (sp_generation == sockpool_generation ) {
3311- if ((sockpool_place_fd_in_pool (sockpool_fd )) != 0 ) {
3312- closeit = 1 ;
3313- }
3314- } else {
3315- sockpool_remove_fd (sockpool_fd );
3316- closeit = 1 ;
3317- }
3262+ do_close = sockpool_place_fd_in_pool (sockpool_fd );
33183263 pthread_mutex_unlock (& cdb2_sockpool_mutex );
3319- if (closeit )
3264+ if (do_close )
33203265 close (sockpool_fd );
33213266 sockpool_fd = -1 ;
33223267 }
0 commit comments