Commit 229656b1efb42b168b9712bc8fe04126640122c0

Authored by Perry Werneck
1 parent a15d2dbb

Updating timeout controller to use the new chained list methods.

src/core/iocalls.c
@@ -139,12 +139,13 @@ static void * internal_add_timer(H3270 *session, unsigned long interval_ms, int @@ -139,12 +139,13 @@ static void * internal_add_timer(H3270 *session, unsigned long interval_ms, int
139 t_new = (timeout_t *) lib3270_malloc(sizeof(timeout_t)); 139 t_new = (timeout_t *) lib3270_malloc(sizeof(timeout_t));
140 140
141 t_new->proc = proc; 141 t_new->proc = proc;
142 - t_new->session = session;  
143 t_new->in_play = False; 142 t_new->in_play = False;
144 143
145 #if defined(_WIN32) 144 #if defined(_WIN32)
  145 +
146 ms_ts(&t_new->ts); 146 ms_ts(&t_new->ts);
147 t_new->ts += interval_ms; 147 t_new->ts += interval_ms;
  148 +
148 #else 149 #else
149 150
150 gettimeofday(&t_new->tv, NULL); 151 gettimeofday(&t_new->tv, NULL);
@@ -156,10 +157,11 @@ static void * internal_add_timer(H3270 *session, unsigned long interval_ms, int @@ -156,10 +157,11 @@ static void * internal_add_timer(H3270 *session, unsigned long interval_ms, int
156 t_new->tv.tv_sec += t_new->tv.tv_usec / MILLION; 157 t_new->tv.tv_sec += t_new->tv.tv_usec / MILLION;
157 t_new->tv.tv_usec %= MILLION; 158 t_new->tv.tv_usec %= MILLION;
158 } 159 }
  160 +
159 #endif /*]*/ 161 #endif /*]*/
160 162
161 /* Find where to insert this item. */ 163 /* Find where to insert this item. */
162 - for (t = session->timeouts; t != TN; t = t->next) 164 + for (t = (timeout_t *) session->timeouts.first; t != TN; t = t->next)
163 { 165 {
164 #if defined(_WIN32) 166 #if defined(_WIN32)
165 if (t->ts > t_new->ts) 167 if (t->ts > t_new->ts)
@@ -173,17 +175,20 @@ static void * internal_add_timer(H3270 *session, unsigned long interval_ms, int @@ -173,17 +175,20 @@ static void * internal_add_timer(H3270 *session, unsigned long interval_ms, int
173 175
174 // Insert it. 176 // Insert it.
175 if (prev == TN) 177 if (prev == TN)
176 - { // Front.  
177 - t_new->next = session->timeouts;  
178 - session->timeouts = t_new; 178 + {
  179 + // t_new is Front.
  180 + t_new->next = (timeout_t *) session->timeouts.first;
  181 + session->timeouts.first = t_new;
179 } 182 }
180 else if (t == TN) 183 else if (t == TN)
181 - { // Rear. 184 + {
  185 + // t_new is Rear.
182 t_new->next = TN; 186 t_new->next = TN;
183 prev->next = t_new; 187 prev->next = t_new;
  188 + session->timeouts.last = (timeout_t *) t_new;
184 } 189 }
185 else 190 else
186 - { // Middle. 191 + { // t_new is Middle.
187 t_new->next = t; 192 t_new->next = t;
188 prev->next = t_new; 193 prev->next = t_new;
189 } 194 }
@@ -196,10 +201,16 @@ static void * internal_add_timer(H3270 *session, unsigned long interval_ms, int @@ -196,10 +201,16 @@ static void * internal_add_timer(H3270 *session, unsigned long interval_ms, int
196 static void internal_remove_timer(H3270 *session, void * timer) 201 static void internal_remove_timer(H3270 *session, void * timer)
197 { 202 {
198 timeout_t *st = (timeout_t *)timer; 203 timeout_t *st = (timeout_t *)timer;
  204 +
  205 + trace("Removing timeout: %p",st);
  206 +
  207 + if(!st->in_play)
  208 + lib3270_linked_list_delete_node(&session->timeouts,timer);
  209 +
  210 + /*
199 timeout_t *t; 211 timeout_t *t;
200 timeout_t *prev = TN; 212 timeout_t *prev = TN;
201 213
202 - trace("Removing timeout: %p",st);  
203 214
204 if (st->in_play) 215 if (st->in_play)
205 return; 216 return;
@@ -217,6 +228,7 @@ static void internal_remove_timer(H3270 *session, void * timer) @@ -217,6 +228,7 @@ static void internal_remove_timer(H3270 *session, void * timer)
217 } 228 }
218 prev = t; 229 prev = t;
219 } 230 }
  231 + */
220 } 232 }
221 233
222 /* I/O events. */ 234 /* I/O events. */
@@ -225,7 +237,6 @@ static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, vo @@ -225,7 +237,6 @@ static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, vo
225 { 237 {
226 input_t *ip = (input_t *) lib3270_linked_list_append_node(&session->input.list,sizeof(input_t), userdata); 238 input_t *ip = (input_t *) lib3270_linked_list_append_node(&session->input.list,sizeof(input_t), userdata);
227 239
228 - ip->session = session;  
229 ip->enabled = 1; 240 ip->enabled = 1;
230 ip->fd = fd; 241 ip->fd = fd;
231 ip->flag = flag; 242 ip->flag = flag;
src/core/linux/event_dispatcher.c
@@ -104,11 +104,11 @@ retry: @@ -104,11 +104,11 @@ retry:
104 104
105 if (block) 105 if (block)
106 { 106 {
107 - if (hSession->timeouts != TN) 107 + if (hSession->timeouts.first)
108 { 108 {
109 (void) gettimeofday(&now, (void *)NULL); 109 (void) gettimeofday(&now, (void *)NULL);
110 - twait.tv_sec = hSession->timeouts->tv.tv_sec - now.tv_sec;  
111 - twait.tv_usec = hSession->timeouts->tv.tv_usec - now.tv_usec; 110 + twait.tv_sec = ((timeout_t *) hSession->timeouts.first)->tv.tv_sec - now.tv_sec;
  111 + twait.tv_usec = ((timeout_t *) hSession->timeouts.first)->tv.tv_usec - now.tv_usec;
112 if (twait.tv_usec < 0L) { 112 if (twait.tv_usec < 0L) {
113 twait.tv_sec--; 113 twait.tv_sec--;
114 twait.tv_usec += MILLION; 114 twait.tv_usec += MILLION;
@@ -151,7 +151,7 @@ retry: @@ -151,7 +151,7 @@ retry:
151 { 151 {
152 if((ip->flag & LIB3270_IO_FLAG_READ) && FD_ISSET(ip->fd, &rfds)) 152 if((ip->flag & LIB3270_IO_FLAG_READ) && FD_ISSET(ip->fd, &rfds))
153 { 153 {
154 - (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_READ,ip->userdata); 154 + (*ip->call)(hSession,ip->fd,LIB3270_IO_FLAG_READ,ip->userdata);
155 processed_any = True; 155 processed_any = True;
156 if (hSession->input.changed) 156 if (hSession->input.changed)
157 goto retry; 157 goto retry;
@@ -159,7 +159,7 @@ retry: @@ -159,7 +159,7 @@ retry:
159 159
160 if((ip->flag & LIB3270_IO_FLAG_WRITE) && FD_ISSET(ip->fd, &wfds)) 160 if((ip->flag & LIB3270_IO_FLAG_WRITE) && FD_ISSET(ip->fd, &wfds))
161 { 161 {
162 - (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_WRITE,ip->userdata); 162 + (*ip->call)(hSession,ip->fd,LIB3270_IO_FLAG_WRITE,ip->userdata);
163 processed_any = True; 163 processed_any = True;
164 if (hSession->input.changed) 164 if (hSession->input.changed)
165 goto retry; 165 goto retry;
@@ -167,7 +167,7 @@ retry: @@ -167,7 +167,7 @@ retry:
167 167
168 if((ip->flag & LIB3270_IO_FLAG_EXCEPTION) && FD_ISSET(ip->fd, &xfds)) 168 if((ip->flag & LIB3270_IO_FLAG_EXCEPTION) && FD_ISSET(ip->fd, &xfds))
169 { 169 {
170 - (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_EXCEPTION,ip->userdata); 170 + (*ip->call)(hSession,ip->fd,LIB3270_IO_FLAG_EXCEPTION,ip->userdata);
171 processed_any = True; 171 processed_any = True;
172 if (hSession->input.changed) 172 if (hSession->input.changed)
173 goto retry; 173 goto retry;
@@ -176,23 +176,51 @@ retry: @@ -176,23 +176,51 @@ retry:
176 } 176 }
177 177
178 // See what's expired. 178 // See what's expired.
179 - if (hSession->timeouts != TN) 179 + if (hSession->timeouts.first)
180 { 180 {
181 struct timeout *t; 181 struct timeout *t;
182 (void) gettimeofday(&now, (void *)NULL); 182 (void) gettimeofday(&now, (void *)NULL);
183 183
184 - while ((t = hSession->timeouts) != TN) 184 + while(hSession->timeouts.first)
  185 + {
  186 + t = (struct timeout *) hSession->timeouts.first;
  187 +
  188 + if (t->tv.tv_sec < now.tv_sec ||(t->tv.tv_sec == now.tv_sec && t->tv.tv_usec < now.tv_usec))
  189 + {
  190 + t->in_play = True;
  191 + (*t->proc)(hSession);
  192 + processed_any = True;
  193 +
  194 + lib3270_linked_list_delete_node(&hSession->timeouts,t);
  195 +
  196 + }
  197 + else
  198 + {
  199 + break;
  200 + }
  201 +
  202 + }
  203 +
  204 + /*
  205 +
  206 + while ((t = ((timeout_t *) hSession->timeouts.first)) != TN)
185 { 207 {
186 if (t->tv.tv_sec < now.tv_sec ||(t->tv.tv_sec == now.tv_sec && t->tv.tv_usec < now.tv_usec)) 208 if (t->tv.tv_sec < now.tv_sec ||(t->tv.tv_sec == now.tv_sec && t->tv.tv_usec < now.tv_usec))
187 { 209 {
188 - hSession->timeouts = t->next;  
189 t->in_play = True; 210 t->in_play = True;
190 (*t->proc)(t->session); 211 (*t->proc)(t->session);
191 processed_any = True; 212 processed_any = True;
192 - lib3270_free(t);  
193 - } else 213 +
  214 + lib3270_linked_list_delete_node(&hSession->timeouts,t);
  215 +
  216 + }
  217 + else
  218 + {
194 break; 219 break;
  220 + }
195 } 221 }
  222 +
  223 + */
196 } 224 }
197 225
198 if (hSession->input.changed) 226 if (hSession->input.changed)
src/core/session.c
@@ -133,13 +133,7 @@ void lib3270_session_free(H3270 *h) @@ -133,13 +133,7 @@ void lib3270_session_free(H3270 *h)
133 release_pointer(h->tabs); 133 release_pointer(h->tabs);
134 134
135 // Release timeouts 135 // Release timeouts
136 - while(h->timeouts)  
137 - {  
138 - timeout_t *t = h->timeouts;  
139 - h->timeouts = t->next;  
140 -  
141 - lib3270_free(t);  
142 - } 136 + lib3270_linked_list_free(&h->timeouts);
143 137
144 // Release inputs; 138 // Release inputs;
145 lib3270_linked_list_free(&h->input.list); 139 lib3270_linked_list_free(&h->input.list);
src/include/lib3270-internals.h
@@ -287,7 +287,9 @@ struct lib3270_text @@ -287,7 +287,9 @@ struct lib3270_text
287 */ 287 */
288 typedef struct timeout 288 typedef struct timeout
289 { 289 {
290 - struct timeout *next; 290 + LIB3270_LINKED_LIST_HEAD;
  291 +
  292 + unsigned char in_play;
291 293
292 #if defined(_WIN32) /*[*/ 294 #if defined(_WIN32) /*[*/
293 unsigned long long ts; 295 unsigned long long ts;
@@ -297,9 +299,6 @@ typedef struct timeout @@ -297,9 +299,6 @@ typedef struct timeout
297 299
298 int (*proc)(H3270 *session); 300 int (*proc)(H3270 *session);
299 301
300 - H3270 *session;  
301 -  
302 - unsigned char in_play;  
303 } timeout_t; 302 } timeout_t;
304 303
305 304
@@ -313,7 +312,6 @@ typedef struct _input_t @@ -313,7 +312,6 @@ typedef struct _input_t
313 LIB3270_LINKED_LIST_HEAD; 312 LIB3270_LINKED_LIST_HEAD;
314 313
315 unsigned char enabled; 314 unsigned char enabled;
316 - H3270 * session;  
317 int fd; 315 int fd;
318 LIB3270_IO_FLAG flag; 316 LIB3270_IO_FLAG flag;
319 317
@@ -684,7 +682,7 @@ struct _h3270 @@ -684,7 +682,7 @@ struct _h3270
684 } ssl; 682 } ssl;
685 #endif // HAVE_LIBSSL 683 #endif // HAVE_LIBSSL
686 684
687 - timeout_t * timeouts; 685 + struct lib3270_linked_list_head timeouts;
688 686
689 struct 687 struct
690 { 688 {