Commit 1dced1cac1886994c109b4c7fc837d8c131c5414

Authored by Perry Werneck
1 parent ae844c8e

Fixing bug in "auto-reconnect".

src/include/lib3270.h
@@ -308,12 +308,11 @@ @@ -308,12 +308,11 @@
308 { 308 {
309 LIB3270_SSL_UNSECURE, /**< @brief No secure connection */ 309 LIB3270_SSL_UNSECURE, /**< @brief No secure connection */
310 LIB3270_SSL_SECURE, /**< @brief Connection secure with CA check */ 310 LIB3270_SSL_SECURE, /**< @brief Connection secure with CA check */
311 - LIB3270_SSL_NEGOTIATED, /**< @brief Connection secure, no CA or self-signed */ 311 + LIB3270_SSL_NEGOTIATED, /**< @brief Connection secure, no CA, self-signed or expired CRL */
312 LIB3270_SSL_NEGOTIATING, /**< @brief Negotiating SSL */ 312 LIB3270_SSL_NEGOTIATING, /**< @brief Negotiating SSL */
313 LIB3270_SSL_UNDEFINED /**< @brief Undefined */ 313 LIB3270_SSL_UNDEFINED /**< @brief Undefined */
314 } LIB3270_SSL_STATE; 314 } LIB3270_SSL_STATE;
315 315
316 -  
317 /** 316 /**
318 * @brief Field information. 317 * @brief Field information.
319 * 318 *
src/lib3270/host.c
@@ -69,8 +69,9 @@ int lib3270_check_for_auto_reconnect(H3270 *hSession) @@ -69,8 +69,9 @@ int lib3270_check_for_auto_reconnect(H3270 *hSession)
69 if(hSession->auto_reconnect_inprogress) 69 if(hSession->auto_reconnect_inprogress)
70 { 70 {
71 lib3270_write_log(hSession,"3270","Starting auto-reconnect on %s",lib3270_get_url(hSession)); 71 lib3270_write_log(hSession,"3270","Starting auto-reconnect on %s",lib3270_get_url(hSession));
72 - lib3270_reconnect(hSession,0);  
73 - hSession->auto_reconnect_inprogress = 0; 72 + hSession->auto_reconnect_inprogress = 0; // Reset "in-progress" to allow reconnection.
  73 + if(lib3270_reconnect(hSession,0))
  74 + lib3270_write_log(hSession,"3270","Auto-reconnect fails: %s",strerror(errno));
74 } 75 }
75 76
76 return 0; 77 return 0;
src/lib3270/linux/connect.c
@@ -297,19 +297,22 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u @@ -297,19 +297,22 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
297 optval = 1; 297 optval = 1;
298 if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0) 298 if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0)
299 { 299 {
  300 + int rc = errno;
300 lib3270_popup_dialog( hSession, 301 lib3270_popup_dialog( hSession,
301 LIB3270_NOTIFY_ERROR, 302 LIB3270_NOTIFY_ERROR,
302 _( "Connection error" ), 303 _( "Connection error" ),
303 _( "setsockopt(SO_OOBINLINE) has failed" ), 304 _( "setsockopt(SO_OOBINLINE) has failed" ),
304 "%s", 305 "%s",
305 - strerror(errno)); 306 + strerror(rc));
306 SOCK_CLOSE(hSession); 307 SOCK_CLOSE(hSession);
307 - return errno = ENOTCONN; 308 + return rc;
308 } 309 }
309 310
310 optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0; 311 optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0;
311 if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) 312 if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0)
312 { 313 {
  314 + int rc = errno;
  315 +
313 char buffer[4096]; 316 char buffer[4096];
314 snprintf(buffer,4095,N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); 317 snprintf(buffer,4095,N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" ));
315 318
@@ -318,9 +321,9 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u @@ -318,9 +321,9 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
318 _( "Connection error" ), 321 _( "Connection error" ),
319 buffer, 322 buffer,
320 "%s", 323 "%s",
321 - strerror(errno)); 324 + strerror(rc));
322 SOCK_CLOSE(hSession); 325 SOCK_CLOSE(hSession);
323 - return errno = ENOTCONN; 326 + return rc;
324 } 327 }
325 else 328 else
326 { 329 {
@@ -375,6 +378,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u @@ -375,6 +378,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
375 378
376 default: 379 default:
377 lib3270_write_log(hSession,"connect", "%s: State changed to unexpected state %d",__FUNCTION__,hSession->cstate); 380 lib3270_write_log(hSession,"connect", "%s: State changed to unexpected state %d",__FUNCTION__,hSession->cstate);
  381 + errno = EINVAL;
378 return -1; 382 return -1;
379 } 383 }
380 384
@@ -382,6 +386,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u @@ -382,6 +386,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
382 386
383 lib3270_disconnect(hSession); 387 lib3270_disconnect(hSession);
384 lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT)); 388 lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT));
  389 +
385 return errno = ETIMEDOUT; 390 return errno = ETIMEDOUT;
386 } 391 }
387 392