diff --git a/src/core/ft/ft.c b/src/core/ft/ft.c index 68e2342..9949544 100644 --- a/src/core/ft/ft.c +++ b/src/core/ft/ft.c @@ -474,7 +474,7 @@ LIB3270_EXPORT int lib3270_ft_start(H3270 *hSession) { // Erase the line and enter the command. flen = kybd_prime(ft->host); if (!flen || flen < strlen(buffer) - 1) { - lib3270_write_log(ft->host, "ft", "Unable to send command \"%s\" (flen=%d szBuffer=%ld)",buffer,flen,strlen(buffer)); + lib3270_write_log(ft->host, "ft", "Unable to send command \"%s\" (flen=%d szBuffer=%u)",buffer,flen,(unsigned int) strlen(buffer)); ft_failed(ft,_( "Unable to send file-transfer request" )); return errno = EINVAL; } diff --git a/src/core/linux/connect.c b/src/core/linux/connect.c index df5cc7b..3ffa953 100644 --- a/src/core/linux/connect.c +++ b/src/core/linux/connect.c @@ -373,46 +373,6 @@ int net_reconnect(H3270 *hSession, int seconds) { lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT)); return errno = rc; } - - /* - time_t end = time(0)+seconds; - - while(time(0) < end) - { - lib3270_main_iterate(hSession,1); - - switch(hSession->connection.state) - { - case LIB3270_PENDING: - case LIB3270_CONNECTED_INITIAL: - case LIB3270_CONNECTED_ANSI: - case LIB3270_CONNECTED_3270: - case LIB3270_CONNECTED_INITIAL_E: - case LIB3270_CONNECTED_NVT: - case LIB3270_CONNECTED_SSCP: - case LIB3270_CONNECTING: - break; - - case LIB3270_NOT_CONNECTED: - return errno = ENOTCONN; - - case LIB3270_CONNECTED_TN3270E: - if(!hSession->starting) - return 0; - break; - - default: - lib3270_write_log(hSession,"connect", "%s: State changed to unexpected state %d",__FUNCTION__,hSession->connection.state); - return errno = EINVAL; - } - - } - - lib3270_disconnect(hSession); - lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT)); - - return errno = ETIMEDOUT; - */ } return 0; diff --git a/src/core/wait.c b/src/core/wait.c index 6b462f6..00e8ad8 100644 --- a/src/core/wait.c +++ b/src/core/wait.c @@ -46,6 +46,7 @@ LIB3270_EXPORT int lib3270_wait_for_update(H3270 GNUC_UNUSED(*hSession), int GNU } LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) { + debug("%s",__FUNCTION__); debug("Session lock state is %d",lib3270_get_lock_status(hSession)); @@ -87,6 +88,7 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) { } int lib3270_wait_for_string(H3270 *hSession, const char *key, int seconds) { + FAIL_IF_NOT_ONLINE(hSession); int rc = 0; @@ -180,6 +182,37 @@ LIB3270_EXPORT int lib3270_wait_for_string_at(H3270 *hSession, unsigned int row, return lib3270_wait_for_string_at_address(hSession,baddr,key,seconds); } +LIB3270_EXPORT int lib3270_wait_for_connected(H3270 *hSession, int seconds) { + + int rc = -1; + int timeout = 0; + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &timeout); + + while(rc == -1) { + if(timeout) { + // Timeout! The timer was destroyed. + return errno = ETIMEDOUT; + } + + if(hSession->connection.state == LIB3270_NOT_CONNECTED) { + rc = ENOTCONN; + break; + } + + if(!hSession->starting && hSession->connection.state >= (int)LIB3270_CONNECTED_INITIAL) { + rc = 0; + break; + } + + lib3270_main_iterate(hSession,1); + + } + RemoveTimer(hSession,timer); + + return errno = rc; +} + + LIB3270_EXPORT int lib3270_wait_for_cstate(H3270 *hSession, LIB3270_CSTATE cstate, int seconds) { int rc = -1; diff --git a/src/include/lib3270.h b/src/include/lib3270.h index b88a817..bc0d54d 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -1061,6 +1061,20 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds); LIB3270_EXPORT int lib3270_wait_for_cstate(H3270 *hSession, LIB3270_CSTATE cstate, int seconds); /** + * @brief Wait "N" seconds for connected state. + * + * @param seconds Number of seconds to wait. + * + * @return 0 if ok, errno code if not. + * + * @retval ETIMEDOUT Timeout waiting. + * @retval ENOTCONN Not connected to host. + * @retval 0 Session is online and in required state. + * + */ +LIB3270_EXPORT int lib3270_wait_for_connected(H3270 *hSession, int seconds); + +/** * "beep" to notify user. * * If available play a sound signal do alert user. -- libgit2 0.21.2