@@ -255,6 +255,22 @@ nc_server_ch_set_dispatch_data(nc_server_ch_session_acquire_ctx_cb acquire_ctx_c
255255 nc_rwlock_unlock (& server_opts .config_lock , __func__ );
256256}
257257
258+ API void
259+ nc_server_ch_set_new_session_fail_cb (nc_server_ch_new_session_fail_cb new_session_fail_cb ,
260+ void * new_session_fail_cb_data )
261+ {
262+ /* CONFIG WRITE LOCK */
263+ if (nc_rwlock_lock (& server_opts .config_lock , NC_RWLOCK_WRITE , NC_CONFIG_LOCK_TIMEOUT , __func__ ) != 1 ) {
264+ return ;
265+ }
266+
267+ server_opts .ch_dispatch_data .new_session_fail_cb = new_session_fail_cb ;
268+ server_opts .ch_dispatch_data .new_session_fail_cb_data = new_session_fail_cb_data ;
269+
270+ /* CONFIG WRITE UNLOCK */
271+ nc_rwlock_unlock (& server_opts .config_lock , __func__ );
272+ }
273+
258274#endif
259275
260276int
@@ -3291,7 +3307,7 @@ nc_ch_client_thread(void *arg)
32913307{
32923308 struct nc_server_ch_thread_arg * data = arg ;
32933309 NC_MSG_TYPE msgtype ;
3294- uint8_t cur_attempts = 0 ;
3310+ uint8_t cur_attempts = 0 , max_attempts ;
32953311 uint16_t next_endpt_index , max_wait ;
32963312 char * cur_endpt_name = NULL ;
32973313 struct nc_ch_endpt * cur_endpt ;
@@ -3416,11 +3432,19 @@ nc_ch_client_thread(void *arg)
34163432 }
34173433 } else {
34183434 /* session was not created, wait a little bit and try again */
3435+ ++ cur_attempts ;
34193436 max_wait = client -> max_wait ;
3437+ max_attempts = client -> max_attempts ;
34203438
34213439 /* CONFIG READ UNLOCK */
34223440 nc_rwlock_unlock (& server_opts .config_lock , __func__ );
34233441
3442+ /* failed connection attempt */
3443+ if (data -> new_session_fail_cb ) {
3444+ data -> new_session_fail_cb (data -> client_name , cur_endpt_name , max_attempts , cur_attempts ,
3445+ data -> new_session_fail_cb_data );
3446+ }
3447+
34243448 /* wait for max_wait seconds */
34253449 if (!nc_server_ch_client_thread_is_running_wait (session , data , max_wait )) {
34263450 /* thread should stop running */
@@ -3439,8 +3463,6 @@ nc_ch_client_thread(void *arg)
34393463 goto cleanup_unlock ;
34403464 }
34413465
3442- ++ cur_attempts ;
3443-
34443466 /* try to find our endpoint again */
34453467 LY_ARRAY_FOR (client -> ch_endpts , next_endpt_index ) {
34463468 if (!strcmp (client -> ch_endpts [next_endpt_index ].name , cur_endpt_name )) {
@@ -3555,6 +3577,8 @@ _nc_connect_ch_client_dispatch(const struct nc_ch_client *ch_client, nc_server_c
35553577 arg -> ctx_cb_data = ctx_cb_data ;
35563578 arg -> new_session_cb = new_session_cb ;
35573579 arg -> new_session_cb_data = new_session_cb_data ;
3580+ arg -> new_session_fail_cb = server_opts .ch_dispatch_data .new_session_fail_cb ;
3581+ arg -> new_session_fail_cb_data = server_opts .ch_dispatch_data .new_session_fail_cb_data ;
35583582 pthread_cond_init (& arg -> cond , NULL );
35593583 pthread_mutex_init (& arg -> cond_lock , NULL );
35603584
0 commit comments