session server BUGFIX limit number of connect retries
... with a single socket.
Refs cesnet/netopeer2#823
diff --git a/src/session_server.c b/src/session_server.c
index 9c1698e..6ba051a 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -3075,8 +3075,15 @@
struct timespec ts_cur;
char *ip_host;
- sock = nc_sock_connect(endpt->address, endpt->port, 5, &endpt->ka, &endpt->sock_pending, &ip_host);
+ sock = nc_sock_connect(endpt->address, endpt->port, NC_SOCKET_CH_TIMEOUT, &endpt->ka, &endpt->sock_pending, &ip_host);
if (sock < 0) {
+ ++endpt->sock_retries;
+ if (endpt->sock_retries == NC_SOCKET_CH_RETRIES) {
+ ERR("Failed to connect socket %d after %d retries, closing.", endpt->sock_pending, NC_SOCKET_CH_RETRIES);
+ close(endpt->sock_pending);
+ endpt->sock_pending = -1;
+ endpt->sock_retries = 0;
+ }
return NC_MSG_ERROR;
}
/* no need to store the socket as pending any longer */