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