Commit f553333fb0698e2cbbd4b670ea5bf458edc24865

Authored by Perry Werneck
1 parent 3ecfb738

Fixing timers.

src/core/linux/event_dispatcher.c
@@ -189,10 +189,8 @@ retry: @@ -189,10 +189,8 @@ retry:
189 { 189 {
190 t->in_play = True; 190 t->in_play = True;
191 191
192 - if((*t->proc)(hSession,t->userdata) == 0)  
193 - lib3270_linked_list_delete_node(&hSession->timeouts,t);  
194 - else  
195 - t->in_play = False; 192 + (*t->proc)(hSession,t->userdata);
  193 + lib3270_linked_list_delete_node(&hSession->timeouts,t);
196 194
197 processed_any = True; 195 processed_any = True;
198 196
src/core/wait.c
@@ -37,8 +37,8 @@ @@ -37,8 +37,8 @@
37 37
38 static int timer_expired(H3270 GNUC_UNUSED(*hSession), void *userdata) 38 static int timer_expired(H3270 GNUC_UNUSED(*hSession), void *userdata)
39 { 39 {
40 - *((int *) userdata) = errno = ETIMEDOUT;  
41 - return 1; // Keep timer handle. 40 + *((int *) userdata) = 1;
  41 + return 0;
42 } 42 }
43 43
44 LIB3270_EXPORT int lib3270_wait_for_update(H3270 GNUC_UNUSED(*hSession), int GNUC_UNUSED(seconds)) 44 LIB3270_EXPORT int lib3270_wait_for_update(H3270 GNUC_UNUSED(*hSession), int GNUC_UNUSED(seconds))
@@ -51,10 +51,16 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) @@ -51,10 +51,16 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds)
51 FAIL_IF_NOT_ONLINE(hSession); 51 FAIL_IF_NOT_ONLINE(hSession);
52 52
53 int rc = 0; 53 int rc = 0;
54 - void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &rc); 54 + int timeout = 0;
  55 + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &timeout);
55 56
56 while(!rc) 57 while(!rc)
57 { 58 {
  59 + if(timeout) {
  60 + // Timeout! The timer was destroyed.
  61 + return errno = ETIMEDOUT;
  62 + }
  63 +
58 if(!lib3270_get_lock_status(hSession)) 64 if(!lib3270_get_lock_status(hSession))
59 { 65 {
60 break; 66 break;
@@ -85,10 +91,16 @@ int lib3270_wait_for_string(H3270 *hSession, const char *key, int seconds) @@ -85,10 +91,16 @@ int lib3270_wait_for_string(H3270 *hSession, const char *key, int seconds)
85 FAIL_IF_NOT_ONLINE(hSession); 91 FAIL_IF_NOT_ONLINE(hSession);
86 92
87 int rc = 0; 93 int rc = 0;
88 - void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &rc); 94 + int timeout = 0;
  95 + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &timeout);
89 96
90 while(!rc) 97 while(!rc)
91 { 98 {
  99 + if(timeout) {
  100 + // Timeout! The timer was destroyed.
  101 + return errno = ETIMEDOUT;
  102 + }
  103 +
92 // Keyboard is locked by operator error, fails! 104 // Keyboard is locked by operator error, fails!
93 if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) 105 if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession))
94 { 106 {
@@ -133,10 +145,16 @@ int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *k @@ -133,10 +145,16 @@ int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *k
133 baddr = lib3270_get_cursor_address(hSession); 145 baddr = lib3270_get_cursor_address(hSession);
134 146
135 int rc = 0; 147 int rc = 0;
136 - void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &rc); 148 + int timeout = 0;
  149 + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &timeout);
137 150
138 while(!rc) 151 while(!rc)
139 { 152 {
  153 + if(timeout) {
  154 + // Timeout! The timer was destroyed.
  155 + return errno = ETIMEDOUT;
  156 + }
  157 +
140 // Keyboard is locked by operator error, fails! 158 // Keyboard is locked by operator error, fails!
141 if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) 159 if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession))
142 { 160 {