diff --git a/src/core/host.c b/src/core/host.c index 384b351..18aa7a5 100644 --- a/src/core/host.c +++ b/src/core/host.c @@ -60,6 +60,7 @@ #include #include #include +#include /** * @brief Called from timer to attempt an automatic reconnection. @@ -209,6 +210,7 @@ void lib3270_set_disconnected(H3270 *hSession) lib3270_set_cstate(hSession,LIB3270_NOT_CONNECTED); mcursor_set(hSession,LIB3270_POINTER_LOCKED); + hSession->kybdlock = LIB3270_KL_NOT_CONNECTED; hSession->starting = 0; #if defined(HAVE_LIBSSL) diff --git a/src/core/keyboard/kybd.c b/src/core/keyboard/kybd.c index 2e5364f..78dbd06 100644 --- a/src/core/keyboard/kybd.c +++ b/src/core/keyboard/kybd.c @@ -2240,25 +2240,3 @@ int kybd_prime(H3270 *hSession) } #endif /*]*/ -LIB3270_EXPORT LIB3270_KEYBOARD_LOCK_STATE lib3270_wait_for_keyboard_unlock(H3270 *hSession, int seconds) -{ - time_t end = time(0)+seconds; - - lib3270_main_iterate(hSession,0); - - do - { - if(!lib3270_is_connected(hSession)) - return LIB3270_KL_NOT_CONNECTED; - - if(KYBDLOCK_IS_OERR(hSession)) - break; - - lib3270_main_iterate(hSession,1); - - } - while(hSession->kybdlock && time(0) < end); - - return (LIB3270_KEYBOARD_LOCK_STATE) hSession->kybdlock; -} - diff --git a/src/core/wait.c b/src/core/wait.c index 7adb4fd..d483a1e 100644 --- a/src/core/wait.c +++ b/src/core/wait.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "kybdc.h" #include "utilc.h" @@ -232,3 +233,41 @@ LIB3270_EXPORT int lib3270_wait_for_cstate(H3270 *hSession, LIB3270_CSTATE cstat return errno = rc; } + +LIB3270_EXPORT LIB3270_KEYBOARD_LOCK_STATE lib3270_wait_for_keyboard_unlock(H3270 *hSession, int seconds) +{ + debug("Session lock state is %d",lib3270_get_lock_status(hSession)); + + int rc = 0; + int timeout = 0; + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &timeout); + + while(!rc) + { + if(timeout) { + // Timeout! The timer was destroyed. + debug("%s exits with ETIMEDOUT",__FUNCTION__); + errno = ETIMEDOUT; + return (LIB3270_KEYBOARD_LOCK_STATE) hSession->kybdlock; + } + + if(lib3270_is_disconnected(hSession)) + { + errno = ENOTCONN; + break; + } + + if(KYBDLOCK_IS_OERR(hSession)) + break; + + debug("%s: Waiting",__FUNCTION__); + lib3270_main_iterate(hSession,1); + + } + + RemoveTimer(hSession,timer); + + debug("%s exits with rc=%d",__FUNCTION__,rc); + return (LIB3270_KEYBOARD_LOCK_STATE) hSession->kybdlock; + +} -- libgit2 0.21.2