diff --git a/host.c b/host.c index 465e1e2..2e84cea 100644 --- a/host.c +++ b/host.c @@ -546,9 +546,8 @@ static int do_connect(H3270 *hSession, const char *n) /* Attempt contact. */ hSession->ever_3270 = False; - hSession->net_sock = net_connect(hSession, chost, port, 0, &resolving,&pending); - if (hSession->net_sock < 0 && !resolving) + if(net_connect(hSession, chost, port, 0, &resolving,&pending) < 0 && !resolving) { /* Redundantly signal a disconnect. */ host_disconnected(hSession); @@ -573,7 +572,7 @@ static int do_connect(H3270 *hSession, const char *n) // login_macro(ps); /* Prepare Xt for I/O. */ - x_add_input(hSession,hSession->net_sock); + x_add_input(hSession,hSession->sock); /* Set state and tell the world. */ if (pending) @@ -662,8 +661,7 @@ void host_disconnect(H3270 *h, int failed) if (CONNECTED || HALF_CONNECTED) { x_remove_input(h); - net_disconnect(); - h->net_sock = -1; + net_disconnect(h); Trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,toggled(RECONNECT),h->auto_reconnect_inprogress); if (toggled(RECONNECT) && !h->auto_reconnect_inprogress) diff --git a/telnet.c b/telnet.c index 2530dff..c91388f 100644 --- a/telnet.c +++ b/telnet.c @@ -913,33 +913,34 @@ static void output_possible(H3270 *session) * net_disconnect * Shut down the socket. */ -void net_disconnect(void) +void net_disconnect(H3270 *session) { #if defined(HAVE_LIBSSL) - if (h3270.ssl_con != NULL) + if(session->ssl_con != NULL) { - SSL_shutdown(h3270.ssl_con); - SSL_free(h3270.ssl_con); - h3270.ssl_con = NULL; + SSL_shutdown(session->ssl_con); + SSL_free(session->ssl_con); + session->ssl_con = NULL; } #endif - set_ssl_state(&h3270,LIB3270_SSL_UNSECURE); - - if (CONNECTED) - (void) shutdown(h3270.sock, 2); + set_ssl_state(session,LIB3270_SSL_UNSECURE); - (void) SOCK_CLOSE(h3270.sock); + if(session->sock >= 0) + { + shutdown(session->sock, 2); + SOCK_CLOSE(session->sock); + session->sock = -1; + } - h3270.sock = -1; trace_dsn("SENT disconnect\n"); /* Restore terminal type to its default. */ if (appres.termname == CN) - h3270.termtype = h3270.full_model_name; + session->termtype = session->full_model_name; /* We're not connected to an LU any more. */ - h3270.connected_lu = CN; + session->connected_lu = CN; status_lu(&h3270,CN); #if !defined(_WIN32) /*[*/ @@ -3400,7 +3401,7 @@ static void continue_tls(unsigned char *sbbuf, int len) /* Trace the junk. */ trace_dsn("%s ? %s\n", opt(TELOPT_STARTTLS), cmd(SE)); popup_an_error(NULL,"TLS negotiation failure"); - net_disconnect(); + net_disconnect(&h3270); return; } @@ -3412,7 +3413,7 @@ static void continue_tls(unsigned char *sbbuf, int len) if(h3270.ssl_con == NULL) { /* Failed. */ - net_disconnect(); + net_disconnect(&h3270); return; } @@ -3438,7 +3439,7 @@ static void continue_tls(unsigned char *sbbuf, int len) if (rv != 1) { trace_dsn("continue_tls: SSL_connect failed\n"); - net_disconnect(); + net_disconnect(&h3270); return; } diff --git a/telnetc.h b/telnetc.h index 9a1d384..e862ac9 100644 --- a/telnetc.h +++ b/telnetc.h @@ -35,7 +35,7 @@ LIB3270_INTERNAL void net_add_eor(unsigned char *buf, int len); LIB3270_INTERNAL void net_break(void); LIB3270_INTERNAL void net_charmode(void); LIB3270_INTERNAL int net_connect(H3270 *session, const char *, char *, Boolean, Boolean *, Boolean *); -LIB3270_INTERNAL void net_disconnect(void); +LIB3270_INTERNAL void net_disconnect(H3270 *session); LIB3270_INTERNAL void net_exception(H3270 *session); LIB3270_INTERNAL void net_hexansi_out(unsigned char *buf, int len); LIB3270_INTERNAL void net_input(H3270 *session); -- libgit2 0.21.2