Commit 82810a20f9f37ae80fc94a373060e6ae4a93e5b7
1 parent
a2141889
Exists in
master
and in
5 other branches
Isolando filas por sessão.
Showing
2 changed files
with
79 additions
and
64 deletions
Show diff stats
src/lib3270/iocalls.c
... | ... | @@ -80,41 +80,8 @@ static void internal_ring_bell(H3270 *session); |
80 | 80 | |
81 | 81 | /*---[ Typedefs ]-------------------------------------------------------------------------------------------*/ |
82 | 82 | |
83 | - typedef struct timeout | |
84 | - { | |
85 | - struct timeout *next; | |
86 | -#if defined(_WIN32) /*[*/ | |
87 | - unsigned long long ts; | |
88 | -#else /*][*/ | |
89 | - struct timeval tv; | |
90 | -#endif /*]*/ | |
91 | - void (*proc)(H3270 *session); | |
92 | - H3270 *session; | |
93 | - Boolean in_play; | |
94 | - } timeout_t; | |
95 | - | |
96 | 83 | #define TN (timeout_t *)NULL |
97 | 84 | |
98 | -/* I/O events. */ | |
99 | -typedef struct input | |
100 | -{ | |
101 | - struct input * next; | |
102 | - H3270 * session; | |
103 | - int fd; | |
104 | - LIB3270_IO_FLAG flag; | |
105 | - void * userdata; | |
106 | - | |
107 | - void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); | |
108 | - | |
109 | -} input_t; | |
110 | - | |
111 | - | |
112 | -/*---[ Statics ]--------------------------------------------------------------------------------------------*/ | |
113 | - | |
114 | - static timeout_t * timeouts = NULL; | |
115 | - static input_t * inputs = NULL; | |
116 | - static Boolean inputs_changed = False; | |
117 | - | |
118 | 85 | /*---[ Implement ]------------------------------------------------------------------------------------------*/ |
119 | 86 | |
120 | 87 | |
... | ... | @@ -165,7 +132,7 @@ static void * internal_add_timeout(H3270 *session, unsigned long interval_ms, vo |
165 | 132 | #endif /*]*/ |
166 | 133 | |
167 | 134 | /* Find where to insert this item. */ |
168 | - for (t = timeouts; t != TN; t = t->next) | |
135 | + for (t = session->timeouts; t != TN; t = t->next) | |
169 | 136 | { |
170 | 137 | #if defined(_WIN32) |
171 | 138 | if (t->ts > t_new->ts) |
... | ... | @@ -180,8 +147,8 @@ static void * internal_add_timeout(H3270 *session, unsigned long interval_ms, vo |
180 | 147 | // Insert it. |
181 | 148 | if (prev == TN) |
182 | 149 | { // Front. |
183 | - t_new->next = timeouts; | |
184 | - timeouts = t_new; | |
150 | + t_new->next = session->timeouts; | |
151 | + session->timeouts = t_new; | |
185 | 152 | } |
186 | 153 | else if (t == TN) |
187 | 154 | { // Rear. |
... | ... | @@ -210,14 +177,14 @@ static void internal_remove_timeout(H3270 *session, void * timer) |
210 | 177 | if (st->in_play) |
211 | 178 | return; |
212 | 179 | |
213 | - for (t = timeouts; t != TN; t = t->next) | |
180 | + for (t = session->timeouts; t != TN; t = t->next) | |
214 | 181 | { |
215 | 182 | if (t == st) |
216 | 183 | { |
217 | 184 | if (prev != TN) |
218 | 185 | prev->next = t->next; |
219 | 186 | else |
220 | - timeouts = t->next; | |
187 | + session->timeouts = t->next; | |
221 | 188 | lib3270_free(t); |
222 | 189 | return; |
223 | 190 | } |
... | ... | @@ -231,14 +198,14 @@ static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, vo |
231 | 198 | { |
232 | 199 | input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); |
233 | 200 | |
234 | - ip->session = session; | |
235 | - ip->fd = fd; | |
236 | - ip->flag = flag; | |
237 | - ip->userdata = userdata; | |
238 | - ip->call = call; | |
201 | + ip->session = session; | |
202 | + ip->fd = fd; | |
203 | + ip->flag = flag; | |
204 | + ip->userdata = userdata; | |
205 | + ip->call = call; | |
239 | 206 | |
240 | - inputs = ip; | |
241 | - inputs_changed = True; | |
207 | + session->inputs = ip; | |
208 | + session->inputs_changed = 1; | |
242 | 209 | |
243 | 210 | return ip; |
244 | 211 | } |
... | ... | @@ -248,7 +215,7 @@ static void internal_remove_poll(H3270 *session, void *id) |
248 | 215 | input_t *ip; |
249 | 216 | input_t *prev = (input_t *)NULL; |
250 | 217 | |
251 | - for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) | |
218 | + for (ip = session->inputs; ip != (input_t *)NULL; ip = ip->next) | |
252 | 219 | { |
253 | 220 | if (ip == (input_t *)id) |
254 | 221 | break; |
... | ... | @@ -265,10 +232,10 @@ static void internal_remove_poll(H3270 *session, void *id) |
265 | 232 | if (prev != (input_t *)NULL) |
266 | 233 | prev->next = ip->next; |
267 | 234 | else |
268 | - inputs = ip->next; | |
235 | + session->inputs = ip->next; | |
269 | 236 | |
270 | 237 | lib3270_free(ip); |
271 | - inputs_changed = True; | |
238 | + session->inputs_changed = 1; | |
272 | 239 | } |
273 | 240 | |
274 | 241 | LIB3270_EXPORT void lib3270_remove_poll(H3270 *session, void *id) { |
... | ... | @@ -281,7 +248,7 @@ LIB3270_EXPORT void lib3270_remove_poll_fd(H3270 *session, int fd) |
281 | 248 | |
282 | 249 | input_t *ip; |
283 | 250 | |
284 | - for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) | |
251 | + for (ip = session->inputs; ip != (input_t *)NULL; ip = ip->next) | |
285 | 252 | { |
286 | 253 | if(ip->fd == fd) |
287 | 254 | { |
... | ... | @@ -299,7 +266,7 @@ LIB3270_EXPORT void lib3270_update_poll_fd(H3270 *session, int fd, LIB3270_IO_F |
299 | 266 | |
300 | 267 | input_t *ip; |
301 | 268 | |
302 | - for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) | |
269 | + for (ip = session->inputs; ip != (input_t *)NULL; ip = ip->next) | |
303 | 270 | { |
304 | 271 | if(ip->fd == fd) |
305 | 272 | { |
... | ... | @@ -337,7 +304,7 @@ int lib3270_default_event_dispatcher(H3270 *hSession, int block) |
337 | 304 | |
338 | 305 | retry: |
339 | 306 | |
340 | - inputs_changed = 0; | |
307 | + hSession->inputs_changed = 0; | |
341 | 308 | |
342 | 309 | // If we've processed any input, then don't block again. |
343 | 310 | if(processed_any) |
... | ... | @@ -454,7 +421,7 @@ retry: |
454 | 421 | FD_ZERO(&wfds); |
455 | 422 | FD_ZERO(&xfds); |
456 | 423 | |
457 | - for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) | |
424 | + for (ip = hSession->inputs; ip != (input_t *)NULL; ip = ip->next) | |
458 | 425 | { |
459 | 426 | if(ip->flag & LIB3270_IO_FLAG_READ) |
460 | 427 | { |
... | ... | @@ -477,11 +444,11 @@ retry: |
477 | 444 | |
478 | 445 | if (block) |
479 | 446 | { |
480 | - if (timeouts != TN) | |
447 | + if (hSession->timeouts != TN) | |
481 | 448 | { |
482 | 449 | (void) gettimeofday(&now, (void *)NULL); |
483 | - twait.tv_sec = timeouts->tv.tv_sec - now.tv_sec; | |
484 | - twait.tv_usec = timeouts->tv.tv_usec - now.tv_usec; | |
450 | + twait.tv_sec = hSession->timeouts->tv.tv_sec - now.tv_sec; | |
451 | + twait.tv_usec = hSession->timeouts->tv.tv_usec - now.tv_usec; | |
485 | 452 | if (twait.tv_usec < 0L) { |
486 | 453 | twait.tv_sec--; |
487 | 454 | twait.tv_usec += MILLION; |
... | ... | @@ -520,13 +487,13 @@ retry: |
520 | 487 | } |
521 | 488 | else |
522 | 489 | { |
523 | - for (ip = inputs; ip != (input_t *) NULL; ip = ip->next) | |
490 | + for (ip = hSession->inputs; ip != (input_t *) NULL; ip = ip->next) | |
524 | 491 | { |
525 | 492 | if((ip->flag & LIB3270_IO_FLAG_READ) && FD_ISSET(ip->fd, &rfds)) |
526 | 493 | { |
527 | 494 | (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_READ,ip->userdata); |
528 | 495 | processed_any = True; |
529 | - if (inputs_changed) | |
496 | + if (hSession->inputs_changed) | |
530 | 497 | goto retry; |
531 | 498 | } |
532 | 499 | |
... | ... | @@ -534,7 +501,7 @@ retry: |
534 | 501 | { |
535 | 502 | (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_WRITE,ip->userdata); |
536 | 503 | processed_any = True; |
537 | - if (inputs_changed) | |
504 | + if (hSession->inputs_changed) | |
538 | 505 | goto retry; |
539 | 506 | } |
540 | 507 | |
... | ... | @@ -542,7 +509,7 @@ retry: |
542 | 509 | { |
543 | 510 | (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_EXCEPTION,ip->userdata); |
544 | 511 | processed_any = True; |
545 | - if (inputs_changed) | |
512 | + if (hSession->inputs_changed) | |
546 | 513 | goto retry; |
547 | 514 | } |
548 | 515 | } |
... | ... | @@ -551,7 +518,7 @@ retry: |
551 | 518 | #endif |
552 | 519 | |
553 | 520 | // See what's expired. |
554 | - if (timeouts != TN) | |
521 | + if (hSession->timeouts != TN) | |
555 | 522 | { |
556 | 523 | #if defined(_WIN32) |
557 | 524 | struct timeout *t; |
... | ... | @@ -561,7 +528,7 @@ retry: |
561 | 528 | (void) gettimeofday(&now, (void *)NULL); |
562 | 529 | #endif |
563 | 530 | |
564 | - while ((t = timeouts) != TN) | |
531 | + while ((t = hSession->timeouts) != TN) | |
565 | 532 | { |
566 | 533 | #if defined(_WIN32) |
567 | 534 | if (t->ts <= now) |
... | ... | @@ -569,7 +536,7 @@ retry: |
569 | 536 | if (t->tv.tv_sec < now.tv_sec ||(t->tv.tv_sec == now.tv_sec && t->tv.tv_usec < now.tv_usec)) |
570 | 537 | #endif |
571 | 538 | { |
572 | - timeouts = t->next; | |
539 | + hSession->timeouts = t->next; | |
573 | 540 | t->in_play = True; |
574 | 541 | (*t->proc)(t->session); |
575 | 542 | processed_any = True; |
... | ... | @@ -579,7 +546,7 @@ retry: |
579 | 546 | } |
580 | 547 | } |
581 | 548 | |
582 | - if (inputs_changed) | |
549 | + if (hSession->inputs_changed) | |
583 | 550 | goto retry; |
584 | 551 | |
585 | 552 | return processed_any; | ... | ... |
src/lib3270/private.h
... | ... | @@ -245,8 +245,52 @@ struct lib3270_text |
245 | 245 | |
246 | 246 | #define LIB3270_TELNET_N_OPTS 256 |
247 | 247 | |
248 | +/** | |
249 | + * | |
250 | + * @brief Timeout control structure. | |
251 | + * | |
252 | + */ | |
253 | +typedef struct timeout | |
254 | +{ | |
255 | + struct timeout *next; | |
256 | + | |
257 | +#if defined(_WIN32) /*[*/ | |
258 | + unsigned long long ts; | |
259 | +#else /*][*/ | |
260 | + struct timeval tv; | |
261 | +#endif /*]*/ | |
262 | + | |
263 | + void (*proc)(H3270 *session); | |
264 | + | |
265 | + H3270 *session; | |
248 | 266 | |
249 | -/** @brief lib3270 session data */ | |
267 | + unsigned char in_play; | |
268 | +} timeout_t; | |
269 | + | |
270 | + | |
271 | +/** | |
272 | + * | |
273 | + * @brief I/O events. | |
274 | + * | |
275 | + */ | |
276 | +typedef struct input | |
277 | +{ | |
278 | + struct input * next; | |
279 | + H3270 * session; | |
280 | + int fd; | |
281 | + LIB3270_IO_FLAG flag; | |
282 | + void * userdata; | |
283 | + | |
284 | + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); | |
285 | + | |
286 | +} input_t; | |
287 | + | |
288 | + | |
289 | +/** | |
290 | + * | |
291 | + * @brief lib3270 session data | |
292 | + * | |
293 | + */ | |
250 | 294 | struct _h3270 |
251 | 295 | { |
252 | 296 | struct lib3270_session_callbacks cbk; // Callback table - Always the first one. |
... | ... | @@ -555,6 +599,10 @@ struct _h3270 |
555 | 599 | unsigned long ssl_error; |
556 | 600 | SSL * ssl_con; |
557 | 601 | |
602 | + timeout_t * timeouts; | |
603 | + input_t * inputs; | |
604 | + int inputs_changed : 1; | |
605 | + | |
558 | 606 | // Callbacks. |
559 | 607 | struct lib3270_state_callback * st_callbacks[LIB3270_STATE_USER]; |
560 | 608 | struct lib3270_state_callback * st_last[LIB3270_STATE_USER]; | ... | ... |