@@ -502,14 +502,14 @@ sock_host_inet6(const struct sockaddr_in6 *addr, char **host, uint16_t *port)
502502
503503int
504504nc_sock_accept_binds (struct nc_bind * binds , uint16_t bind_count , pthread_mutex_t * bind_lock , int timeout , char * * host ,
505- uint16_t * port , uint16_t * idx )
505+ uint16_t * port , uint16_t * idx , int * sock )
506506{
507507 uint16_t i , j , pfd_count , client_port ;
508508 char * client_address ;
509509 struct pollfd * pfd ;
510510 struct sockaddr_storage saddr ;
511511 socklen_t saddr_len = sizeof (saddr );
512- int ret , client_sock , sock = -1 , flags ;
512+ int ret , client_sock , server_sock = -1 , flags ;
513513
514514 pfd = malloc (bind_count * sizeof * pfd );
515515 NC_CHECK_ERRMEM_RET (!pfd , -1 );
@@ -525,7 +525,7 @@ nc_sock_accept_binds(struct nc_bind *binds, uint16_t bind_count, pthread_mutex_t
525525 if (binds [i ].pollin ) {
526526 binds [i ].pollin = 0 ;
527527 /* leftover pollin */
528- sock = binds [i ].sock ;
528+ server_sock = binds [i ].sock ;
529529 break ;
530530 }
531531 pfd [pfd_count ].fd = binds [i ].sock ;
@@ -535,7 +535,7 @@ nc_sock_accept_binds(struct nc_bind *binds, uint16_t bind_count, pthread_mutex_t
535535 ++ pfd_count ;
536536 }
537537
538- if (sock == -1 ) {
538+ if (server_sock == -1 ) {
539539 /* poll for a new connection */
540540 ret = nc_poll (pfd , pfd_count , timeout );
541541 if (ret < 1 ) {
@@ -558,7 +558,7 @@ nc_sock_accept_binds(struct nc_bind *binds, uint16_t bind_count, pthread_mutex_t
558558
559559 if (!ret ) {
560560 /* the last socket with an event, use it */
561- sock = pfd [j ].fd ;
561+ server_sock = pfd [j ].fd ;
562562 break ;
563563 } else {
564564 /* just remember the event for next time */
@@ -568,15 +568,15 @@ nc_sock_accept_binds(struct nc_bind *binds, uint16_t bind_count, pthread_mutex_t
568568 }
569569 }
570570 free (pfd );
571- if (sock == -1 ) {
571+ if (server_sock == -1 ) {
572572 ERRINT ;
573573 /* UNLOCK */
574574 pthread_mutex_unlock (bind_lock );
575575 return -1 ;
576576 }
577577
578578 /* accept connection */
579- client_sock = accept (sock , (struct sockaddr * )& saddr , & saddr_len );
579+ client_sock = accept (server_sock , (struct sockaddr * )& saddr , & saddr_len );
580580 if (client_sock < 0 ) {
581581 ERR (NULL , "Accept failed (%s)." , strerror (errno ));
582582 /* UNLOCK */
@@ -628,7 +628,9 @@ nc_sock_accept_binds(struct nc_bind *binds, uint16_t bind_count, pthread_mutex_t
628628 }
629629 /* UNLOCK */
630630 pthread_mutex_unlock (bind_lock );
631- return client_sock ;
631+
632+ * sock = client_sock ;
633+ return 1 ;
632634
633635fail :
634636 close (client_sock );
@@ -2302,12 +2304,12 @@ nc_accept(int timeout, const struct ly_ctx *ctx, struct nc_session **session)
23022304 goto cleanup ;
23032305 }
23042306
2305- ret = nc_sock_accept_binds (server_opts .binds , server_opts .endpt_count , & server_opts .bind_lock , timeout , & host , & port , & bind_idx );
2306- if (ret < 0 ) {
2307+ ret = nc_sock_accept_binds (server_opts .binds , server_opts .endpt_count , & server_opts .bind_lock , timeout , & host ,
2308+ & port , & bind_idx , & sock );
2309+ if (ret < 1 ) {
23072310 msgtype = (!ret ? NC_MSG_WOULDBLOCK : NC_MSG_ERROR );
23082311 goto cleanup ;
23092312 }
2310- sock = ret ;
23112313
23122314 /* configure keepalives */
23132315 if (nc_sock_configure_ka (sock , & server_opts .endpts [bind_idx ].ka )) {
0 commit comments