From ac7c7d403370f7068fb998c001bcc6240994f10f Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 25 May 2021 16:25:59 -0300 Subject: [PATCH] Fixing popup on connection error. --- src/core/linux/connect.c | 26 +++++++++++++++++++------- src/testprogram/testprogram.c | 5 +++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/core/linux/connect.c b/src/core/linux/connect.c index 992ad39..df5cc7b 100644 --- a/src/core/linux/connect.c +++ b/src/core/linux/connect.c @@ -177,8 +177,8 @@ int lib3270_network_connect(H3270 *hSession, LIB3270_NETWORK_STATE *state) { } static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG GNUC_UNUSED(flag), void GNUC_UNUSED(*dunno)) { - int err; - socklen_t len = sizeof(err); + int err = 0; + socklen_t len = sizeof(err); if(hSession->xio.write) { trace("%s write=%p",__FUNCTION__,hSession->xio.write); @@ -205,23 +205,35 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG lib3270_popup(hSession,&popup,0); return; + } else if(err) { - lib3270_autoptr(LIB3270_POPUP) popup = - lib3270_popup_clone_printf( - NULL, + + lib3270_disconnect(hSession); + + lib3270_autoptr(char) summary = + lib3270_strdup_printf( _( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc ); - lib3270_autoptr(char) syserror = + lib3270_autoptr(char) body = lib3270_strdup_printf( _("The system error was \"%s\" (rc=%d)"), strerror(err), err ); - if(hSession->cbk.popup(hSession,popup,!hSession->auto_reconnect_inprogress) == 0) + + LIB3270_POPUP popup = { + .type = LIB3270_NOTIFY_ERROR, + .title = _( "Connection error" ), + .summary = summary, + .body = body, + .label = _("_Retry") + }; + + if(lib3270_popup(hSession,&popup,!hSession->auto_reconnect_inprogress) == 0) lib3270_activate_auto_reconnect(hSession,1000); return; diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index 4017d55..83de3f9 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -110,8 +110,9 @@ int main(int argc, char *argv[]) { lib3270_crl_set_preferred_protocol(h,"ldap"); #endif // HAVE_LDAP - if(lib3270_set_url(h,NULL)) - lib3270_set_url(h,"tn3270://127.0.0.1"); + //if(lib3270_set_url(h,NULL)) + // lib3270_set_url(h,"tn3270://127.0.0.1"); + lib3270_set_url(h,"tn3270://localhost:3270"); int long_index =0; int opt; -- libgit2 0.21.2