From 22842162e8b587ff4f4c1df3a9cb853a4409aea5 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 4 Aug 2020 15:50:54 -0300 Subject: [PATCH] Fixing performance issues. --- src/core/actions.cc | 7 +------ src/core/calls.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- src/core/cursor.cc | 11 ++++------- src/core/set.cc | 70 ++-------------------------------------------------------------------- 4 files changed, 68 insertions(+), 91 deletions(-) diff --git a/src/core/actions.cc b/src/core/actions.cc index 21ded6b..ff2f4b7 100644 --- a/src/core/actions.cc +++ b/src/core/actions.cc @@ -36,12 +36,7 @@ try { - TN3270::Host &host = getSession(); - - if(!host.isConnected()) - return HLLAPI_STATUS_DISCONNECTED; - - worker(host); + worker(getSession()); return HLLAPI_STATUS_SUCCESS; diff --git a/src/core/calls.cc b/src/core/calls.cc index 831fc4d..aa20c69 100644 --- a/src/core/calls.cc +++ b/src/core/calls.cc @@ -37,6 +37,10 @@ return atoi(getSession().getRevision().c_str()); + } catch(const std::system_error &e) { + + hllapi_translate_error(e); + } catch(const std::exception &e) { hllapi_lasterror = e.what(); @@ -57,6 +61,10 @@ if(wait) host.wait(TN3270::CONNECTED_TN3270E); + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); + } catch(const std::exception &e) { hllapi_lasterror = e.what(); @@ -79,6 +87,10 @@ return getSession().isConnected(); + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); + } catch(std::exception &e) { hllapi_lasterror = e.what(); @@ -120,6 +132,10 @@ return HLLAPI_STATUS_WAITING; // time-out while still busy (in XCLOCK or XSYSTEM in X) for the 3270 terminal emulation. } + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); + } catch(std::exception &e) { hllapi_lasterror = e.what(); @@ -136,6 +152,10 @@ return (DWORD) getSession().getProgramMessage(); + } catch(const std::system_error &e) { + + hllapi_translate_error(e); + } catch(std::exception &e) { hllapi_lasterror = e.what(); @@ -153,6 +173,10 @@ getSession().disconnect(); + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); + } catch(std::exception &e) { hllapi_lasterror = e.what(); @@ -168,12 +192,12 @@ try { - TN3270::Host &host = getSession(); + getSession().waitForReady((unsigned int) seconds); + return HLLAPI_STATUS_SUCCESS; - if(host.isConnected()) - host.waitForReady((unsigned int) seconds); + } catch(const std::system_error &e) { - return hllapi_get_state(); + return hllapi_translate_error(e); } catch(const std::exception &e) { @@ -193,7 +217,11 @@ host.wait((TN3270::ConnectionState) cstate, (unsigned int) seconds); - return 0; + return HLLAPI_STATUS_SUCCESS; + + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); } catch(const std::exception &e) { @@ -209,12 +237,12 @@ try { - TN3270::Host &host = getSession(); + getSession().waitForChange((unsigned int) seconds); + return HLLAPI_STATUS_SUCCESS; - if(host.isConnected()) - host.waitForChange((unsigned int) seconds); + } catch(const std::system_error &e) { - return hllapi_get_state(); + return hllapi_translate_error(e); } catch(std::exception &e) { @@ -233,6 +261,10 @@ getSession().setCharSet((const char *) charset); return HLLAPI_STATUS_SUCCESS; + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); + } catch(std::exception &e) { hllapi_lasterror = e.what(); @@ -248,8 +280,11 @@ try { getSession().wait(seconds); + return HLLAPI_STATUS_SUCCESS; - return hllapi_get_state(); + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); } catch(std::exception &e) { @@ -267,6 +302,10 @@ return getSession().compare((unsigned int) row, (unsigned int) col, text); + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); + } catch(std::exception &e) { hllapi_lasterror = e.what(); @@ -285,6 +324,10 @@ return HLLAPI_STATUS_SUCCESS; + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); + } catch(std::exception &e) { hllapi_lasterror = e.what(); @@ -301,6 +344,10 @@ return getSession().compare((int) addr, text); + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); + } catch(std::exception &e) { hllapi_lasterror = e.what(); @@ -324,6 +371,10 @@ } + } catch(const std::system_error &e) { + + return hllapi_translate_error(e); + } catch(std::exception &e) { hllapi_lasterror = e.what(); diff --git a/src/core/cursor.cc b/src/core/cursor.cc index 83cf3f1..0ac1aa9 100644 --- a/src/core/cursor.cc +++ b/src/core/cursor.cc @@ -35,16 +35,13 @@ try { - TN3270::Host &host = getSession(); + worker(getSession()); - if(!host.isConnected()) { - hllapi_lasterror = _( "Disconnected from host" ); - return HLLAPI_STATUS_DISCONNECTED; - } + return HLLAPI_STATUS_SUCCESS; - worker(host); + } catch(const std::system_error &e) { - return HLLAPI_STATUS_SUCCESS; + return hllapi_translate_error(e); } catch(const std::exception &e) { diff --git a/src/core/set.cc b/src/core/set.cc index 8848dd4..0338ff8 100644 --- a/src/core/set.cc +++ b/src/core/set.cc @@ -38,74 +38,9 @@ static DWORD set(std::function worker) noexcept { - LIB3270_KEYBOARD_LOCK_STATE kLock = LIB3270_KL_UNLOCKED; - try { - TN3270::Host &host = getSession(); - - switch(host.waitForKeyboardUnlock()) { - case LIB3270_KL_UNLOCKED: - worker(host); - break; - - case LIB3270_KL_NOT_CONNECTED: - hllapi_lasterror = _("Not connected to host"); - return HLLAPI_STATUS_DISCONNECTED; - - case LIB3270_KL_OERR_MASK: - hllapi_lasterror = _("LIB3270_KL_OERR_MASK"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_OERR_PROTECTED: - hllapi_lasterror = _("LIB3270_KL_OERR_PROTECTED"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_OERR_NUMERIC: - hllapi_lasterror = _("LIB3270_KL_OERR_NUMERIC"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_OERR_OVERFLOW: - hllapi_lasterror = _("LIB3270_KL_OERR_OVERFLOW"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_OERR_DBCS: - hllapi_lasterror = _("LIB3270_KL_OERR_DBCS"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_AWAITING_FIRST: - hllapi_lasterror = _("LIB3270_KL_AWAITING_FIRST"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_OIA_TWAIT: - hllapi_lasterror = _("LIB3270_KL_OIA_TWAIT"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_OIA_LOCKED: - hllapi_lasterror = _("LIB3270_KL_OIA_LOCKED"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_DEFERRED_UNLOCK: - hllapi_lasterror = _("LIB3270_KL_DEFERRED_UNLOCK"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_ENTER_INHIBIT: - hllapi_lasterror = _("LIB3270_KL_ENTER_INHIBIT"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_SCROLLED: - hllapi_lasterror = _("LIB3270_KL_SCROLLED"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_KL_OIA_MINUS: - hllapi_lasterror = _("LIB3270_KL_OIA_MINUS"); - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - default: - hllapi_lasterror = _("Unexpected error waiting for keyboard unlock"); - return HLLAPI_STATUS_SYSTEM_ERROR; - } - + worker(getSession()); return HLLAPI_STATUS_SUCCESS; } catch(const std::system_error &e) { @@ -122,11 +57,10 @@ // Unexpected error getting session or lock state hllapi_lasterror = _( "Unexpected error" ); - return HLLAPI_STATUS_SYSTEM_ERROR; } - return hllapi_translate_error(kLock); + return HLLAPI_STATUS_SYSTEM_ERROR; } -- libgit2 0.21.2