From 1dced1cac1886994c109b4c7fc837d8c131c5414 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 17 Jan 2019 13:07:15 -0200 Subject: [PATCH] Fixing bug in "auto-reconnect". --- src/include/lib3270.h | 3 +-- src/lib3270/host.c | 5 +++-- src/lib3270/linux/connect.c | 13 +++++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 1371f47..ca4f5c2 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -308,12 +308,11 @@ { LIB3270_SSL_UNSECURE, /**< @brief No secure connection */ LIB3270_SSL_SECURE, /**< @brief Connection secure with CA check */ - LIB3270_SSL_NEGOTIATED, /**< @brief Connection secure, no CA or self-signed */ + LIB3270_SSL_NEGOTIATED, /**< @brief Connection secure, no CA, self-signed or expired CRL */ LIB3270_SSL_NEGOTIATING, /**< @brief Negotiating SSL */ LIB3270_SSL_UNDEFINED /**< @brief Undefined */ } LIB3270_SSL_STATE; - /** * @brief Field information. * diff --git a/src/lib3270/host.c b/src/lib3270/host.c index ab18658..3e6e7c5 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -69,8 +69,9 @@ int lib3270_check_for_auto_reconnect(H3270 *hSession) if(hSession->auto_reconnect_inprogress) { lib3270_write_log(hSession,"3270","Starting auto-reconnect on %s",lib3270_get_url(hSession)); - lib3270_reconnect(hSession,0); - hSession->auto_reconnect_inprogress = 0; + hSession->auto_reconnect_inprogress = 0; // Reset "in-progress" to allow reconnection. + if(lib3270_reconnect(hSession,0)) + lib3270_write_log(hSession,"3270","Auto-reconnect fails: %s",strerror(errno)); } return 0; diff --git a/src/lib3270/linux/connect.c b/src/lib3270/linux/connect.c index 9f1b0e6..53dc577 100644 --- a/src/lib3270/linux/connect.c +++ b/src/lib3270/linux/connect.c @@ -297,19 +297,22 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u optval = 1; if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0) { + int rc = errno; lib3270_popup_dialog( hSession, LIB3270_NOTIFY_ERROR, _( "Connection error" ), _( "setsockopt(SO_OOBINLINE) has failed" ), "%s", - strerror(errno)); + strerror(rc)); SOCK_CLOSE(hSession); - return errno = ENOTCONN; + return rc; } optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0; if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) { + int rc = errno; + char buffer[4096]; snprintf(buffer,4095,N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); @@ -318,9 +321,9 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u _( "Connection error" ), buffer, "%s", - strerror(errno)); + strerror(rc)); SOCK_CLOSE(hSession); - return errno = ENOTCONN; + return rc; } else { @@ -375,6 +378,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u default: lib3270_write_log(hSession,"connect", "%s: State changed to unexpected state %d",__FUNCTION__,hSession->cstate); + errno = EINVAL; return -1; } @@ -382,6 +386,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u lib3270_disconnect(hSession); lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT)); + return errno = ETIMEDOUT; } -- libgit2 0.21.2