diff --git a/src/core/ctlr.c b/src/core/ctlr.c index f92dbd5..7868104 100644 --- a/src/core/ctlr.c +++ b/src/core/ctlr.c @@ -2696,101 +2696,3 @@ enum dbcs_state ctlr_dbcs_state(int baddr) return dbcs? ea_buf[baddr].db: DBCS_NONE; } #endif /*]*/ - -/* - * Transaction timing. The time between sending an interrupt (PF, PA, Enter, - * Clear) and the host unlocking the keyboard is indicated on the status line - * to an accuracy of 0.1 seconds. If we don't repaint the screen before we see - * the unlock, the time should be fairly accurate. - */ -//static struct timeval t_start; -// static Boolean ticking = False; -//static Boolean mticking = False; -//static void * tick_id; -//static struct timeval t_want; - -/* -/// @brief Return the difference in milliseconds between two timevals. -static long delta_msec(struct timeval *t1, struct timeval *t0) -{ - return (t1->tv_sec - t0->tv_sec) * 1000 + - (t1->tv_usec - t0->tv_usec + 500) / 1000; -} - -static int keep_ticking(H3270 *hSession) -{ - struct timeval t1; - long msec; - - do - { - (void) gettimeofday(&t1, (struct timezone *) 0); - hSession->t_want.tv_sec++; - msec = delta_msec(&hSession->t_want, &t1); - } while (msec <= 0); - - status_timing(hSession,&hSession->t_start, &t1); - - return 1; -} -*/ - -/* -void ticking_start(H3270 *hSession, Boolean anyway) -{ - CHECK_SESSION_HANDLE(hSession); - - if(hSession->cbk.set_timer) - { - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SHOW_TIMING) || anyway) - hSession->cbk.set_timer(hSession,1); - } - else - { - (void) gettimeofday(&hSession->t_start, (struct timezone *) 0); - - hSession->mticking = 1; - - if (!lib3270_get_toggle(hSession,LIB3270_TOGGLE_SHOW_TIMING) && !anyway) - return; - - status_untiming(hSession); - - if (hSession->ticking) - RemoveTimer(hSession, hSession->tick_id); - - hSession->ticking = 1; - hSession->tick_id = AddTimer(1000, hSession, keep_ticking); - hSession->t_want = hSession->t_start; - } - -} -*/ - -/* -static void ticking_stop(H3270 *hSession) -{ - CHECK_SESSION_HANDLE(hSession); - - if(hSession->cbk.set_timer) - { - hSession->cbk.set_timer(hSession,0); - } - else - { - struct timeval t1; - - (void) gettimeofday(&t1, (struct timezone *) 0); - if (hSession->mticking) - hSession->mticking = 0; - else - return; - - if (!hSession->ticking) - return; - RemoveTimer(hSession, hSession->tick_id); - hSession->ticking = 0; - status_timing(hSession,&hSession->t_start, &t1); - } -} -*/ diff --git a/src/core/linux/event_dispatcher.c b/src/core/linux/event_dispatcher.c index 716474c..8964e82 100644 --- a/src/core/linux/event_dispatcher.c +++ b/src/core/linux/event_dispatcher.c @@ -188,10 +188,14 @@ retry: if (t->tv.tv_sec < now.tv_sec ||(t->tv.tv_sec == now.tv_sec && t->tv.tv_usec < now.tv_usec)) { t->in_play = True; - (*t->proc)(hSession,t->userdata); + + if((*t->proc)(hSession,t->userdata) == 0) + lib3270_linked_list_delete_node(&hSession->timeouts,t); + else + t->in_play = False; + processed_any = True; - lib3270_linked_list_delete_node(&hSession->timeouts,t); } else diff --git a/src/core/wait.c b/src/core/wait.c index c4d8ed4..0b1ee25 100644 --- a/src/core/wait.c +++ b/src/core/wait.c @@ -31,9 +31,16 @@ #include #include #include "kybdc.h" +#include "utilc.h" /*---[ Implement ]------------------------------------------------------------------------------------------*/ +static int timer_expired(H3270 GNUC_UNUSED(*hSession), void *userdata) +{ + *((int *) userdata) = errno = ETIMEDOUT; + return 1; // Keep timer handle. +} + LIB3270_EXPORT int lib3270_wait_for_update(H3270 GNUC_UNUSED(*hSession), int GNUC_UNUSED(seconds)) { return errno = ENOTSUP; @@ -41,57 +48,70 @@ LIB3270_EXPORT int lib3270_wait_for_update(H3270 GNUC_UNUSED(*hSession), int GNU LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) { - time_t end = time(0)+seconds; - - if(lib3270_is_disconnected(hSession)) - return errno = ENOTCONN; - - lib3270_main_iterate(hSession,0); + FAIL_IF_NOT_ONLINE(hSession); - // Keyboard is locked by operator error, fails! - if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) - return errno = EPERM; + int rc = 0; + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &rc); - do + while(!rc) { if(!lib3270_get_lock_status(hSession)) - return 0; + { + break; + } if(lib3270_is_disconnected(hSession)) - return errno = ENOTCONN; + { + rc = errno = ENOTCONN; + break; + } - lib3270_main_iterate(hSession,1); + if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) + { + rc = errno = EPERM; + break; + } + lib3270_main_iterate(hSession,1); } - while(time(0) < end); + RemoveTimer(hSession,timer); + + return rc; - return errno = ETIMEDOUT; } int lib3270_wait_for_string(H3270 *hSession, const char *key, int seconds) { - time_t end = time(0)+seconds; - FAIL_IF_NOT_ONLINE(hSession); - lib3270_main_iterate(hSession,0); + int rc = 0; + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &rc); - do + while(!rc) { // Keyboard is locked by operator error, fails! if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) - return errno = EPERM; + { + rc = errno = EPERM; + break; + } if(!lib3270_is_connected(hSession)) - return errno = ENOTCONN; + { + rc = errno = ENOTCONN; + break; + } char * contents = lib3270_get_string_at_address(hSession, 0, -1, 0); if(!contents) - return errno; + { + rc = errno; + break; + } if(strstr(contents,key)) { lib3270_free(contents); - return 0; + break; } lib3270_free(contents); @@ -99,40 +119,48 @@ int lib3270_wait_for_string(H3270 *hSession, const char *key, int seconds) lib3270_main_iterate(hSession,1); } - while(time(0) < end); + RemoveTimer(hSession,timer); + + return rc; - return errno = ETIMEDOUT; } int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *key, int seconds) { - time_t end = time(0)+seconds; - FAIL_IF_NOT_ONLINE(hSession); - lib3270_main_iterate(hSession,0); - if(baddr < 0) baddr = lib3270_get_cursor_address(hSession); - do + int rc = 0; + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &rc); + + while(!rc) { // Keyboard is locked by operator error, fails! if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) - return errno = EPERM; + { + rc = errno = EPERM; + break; + } if(!lib3270_is_connected(hSession)) - return errno = ENOTCONN; + { + rc = errno = ENOTCONN; + break; + } if(lib3270_cmp_string_at_address(hSession, baddr, key, 0) == 0) - return 0; + { + break; + } lib3270_main_iterate(hSession,1); } - while(time(0) < end); + RemoveTimer(hSession,timer); - return errno = ETIMEDOUT; + return rc; } diff --git a/src/include/utilc.h b/src/include/utilc.h index b6fca5d..23a846e 100644 --- a/src/include/utilc.h +++ b/src/include/utilc.h @@ -17,22 +17,11 @@ * @brief Global declarations for util.c. */ -LIB3270_INTERNAL char *ctl_see(int c); +LIB3270_INTERNAL char * ctl_see(int c); - /* -LIB3270_INTERNAL void add_resource(const char *name, const char *value); -LIB3270_INTERNAL const char *get_message(const char *key); -LIB3270_INTERNAL const char *get_fresource(H3270 *hSession, const char *fmt, ...) LIB3270_GNUC_FORMAT(2, 3); -LIB3270_INTERNAL const char *get_resource(H3270 *hSession, const char *name); -LIB3270_INTERNAL int split_dbcs_resource(const char *value, char sep, char **part1, char **part2); -LIB3270_INTERNAL int split_dresource(char **st, char **left, char **right); -LIB3270_INTERNAL int split_lresource(char **st, char **value); -LIB3270_INTERNAL char *strip_whitespace(const char *s); -*/ - -LIB3270_INTERNAL char *xs_buffer(const char *fmt, ...) LIB3270_GNUC_FORMAT(1, 2); -LIB3270_INTERNAL void xs_error(const char *fmt, ...) LIB3270_GNUC_FORMAT(1, 2); -LIB3270_INTERNAL void xs_warning(const char *fmt, ...) LIB3270_GNUC_FORMAT(1, 2); +LIB3270_INTERNAL char * xs_buffer(const char *fmt, ...) LIB3270_GNUC_FORMAT(1, 2); +LIB3270_INTERNAL void xs_error(const char *fmt, ...) LIB3270_GNUC_FORMAT(1, 2); +LIB3270_INTERNAL void xs_warning(const char *fmt, ...) LIB3270_GNUC_FORMAT(1, 2); LIB3270_INTERNAL void * AddInput(int, H3270 *session, void (*fn)(H3270 *session)); LIB3270_INTERNAL void * AddOutput(int, H3270 *session, void (*fn)(H3270 *session)); @@ -42,24 +31,6 @@ LIB3270_INTERNAL void RemoveSource(H3270 *session, void *cookie); LIB3270_INTERNAL void * AddTimer(unsigned long msec, H3270 *session, int (*fn)(H3270 *session, void *userdata), void *userdata); LIB3270_INTERNAL void RemoveTimer(H3270 *session, void *cookie); -// LIB3270_INTERNAL const char * KeysymToString(KeySym k); - -// LIB3270_INTERNAL int read_resource_file(const char *filename, Boolean fatal); -// LIB3270_INTERNAL Boolean split_hier(char *label, char **base, char ***parents); - -/* -typedef struct { - char *buf; - int alloc_len; - int cur_len; -} rpf_t; - -LIB3270_INTERNAL void rpf_init(rpf_t *r); -LIB3270_INTERNAL void rpf_reset(rpf_t *r); -LIB3270_INTERNAL void rpf(rpf_t *r, char *fmt, ...) LIB3270_GNUC_FORMAT(2, 3); -LIB3270_INTERNAL void rpf_free(rpf_t *r); -*/ - /** * @brief "unescape" text (Replaces %value for corresponding character). * @@ -71,7 +42,7 @@ LIB3270_INTERNAL void rpf_free(rpf_t *r); LIB3270_INTERNAL char * lib3270_unescape(const char *text); /** - * @brief Compare strings ignoring non alfanumeric chars. + * @brief Compare strings ignoring non alphanumeric chars. * * @param s1 First string. * @param s2 Second string. -- libgit2 0.21.2