diff --git a/src/core/wait.c b/src/core/wait.c index 0a3f040..5973f75 100644 --- a/src/core/wait.c +++ b/src/core/wait.c @@ -50,6 +50,9 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) { FAIL_IF_NOT_ONLINE(hSession); + debug("%s",__FUNCTION__); + 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); @@ -58,11 +61,14 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) { if(timeout) { // Timeout! The timer was destroyed. + debug("%s exits with ETIMEDOUT",__FUNCTION__); return errno = ETIMEDOUT; } - if(!lib3270_get_lock_status(hSession)) + if(lib3270_get_lock_status(hSession) == LIB3270_MESSAGE_NONE) { + // Is unlocked, break. + break; } @@ -82,6 +88,7 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) } RemoveTimer(hSession,timer); + debug("%s exits with rc=%d",__FUNCTION__,rc); return rc; } diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index 50515c9..21a7440 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -161,9 +161,20 @@ int main(int argc, char *argv[]) { printf("\n\nWaiting starts %u\n",(unsigned int) time(NULL)); lib3270_wait_for_ready(h,10); + + { + // Performance checks + size_t f; + time_t start = time(0); + for(f=0;f < 1000; f++) { + lib3270_wait_for_ready(h,10); + } + printf("Time for 1000 iterations of wait_for_ready was %d\n",(int) (time(0) - start)); + + } + printf("Waiting ends %u\n\n",(unsigned int) time(NULL)); - /* lib3270_enter(h); lib3270_wait(h,5); @@ -185,7 +196,6 @@ int main(int argc, char *argv[]) if(text) printf("Screen:\n[%s]\n",text); } - */ lib3270_disconnect(h); -- libgit2 0.21.2