Commit a15d2dbb33ff5450d857d0419ee62a06d87a43c0

Authored by Perry Werneck
1 parent cf6fe3da

Updating input list to use the new chained list managers.

src/core/iocalls.c
@@ -223,25 +223,26 @@ static void internal_remove_timer(H3270 *session, void * timer) @@ -223,25 +223,26 @@ static void internal_remove_timer(H3270 *session, void * timer)
223 223
224 static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata ) 224 static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata )
225 { 225 {
226 - input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); 226 + input_t *ip = (input_t *) lib3270_linked_list_append_node(&session->input.list,sizeof(input_t), userdata);
227 227
228 ip->session = session; 228 ip->session = session;
229 ip->enabled = 1; 229 ip->enabled = 1;
230 ip->fd = fd; 230 ip->fd = fd;
231 ip->flag = flag; 231 ip->flag = flag;
232 - ip->userdata = userdata;  
233 ip->call = call; 232 ip->call = call;
234 233
235 - ip->next = (input_t *) session->inputs;  
236 -  
237 - session->inputs = ip;  
238 - session->inputs_changed = 1; 234 + session->input.changed = 1;
239 235
240 return ip; 236 return ip;
241 } 237 }
242 238
243 static void internal_remove_poll(H3270 *session, void *id) 239 static void internal_remove_poll(H3270 *session, void *id)
244 { 240 {
  241 + lib3270_linked_list_delete_node(&session->input.list,id);
  242 +
  243 + session->input.changed = 1;
  244 +
  245 + /*
245 input_t *ip; 246 input_t *ip;
246 input_t *prev = (input_t *)NULL; 247 input_t *prev = (input_t *)NULL;
247 248
@@ -266,18 +267,19 @@ static void internal_remove_poll(H3270 *session, void *id) @@ -266,18 +267,19 @@ static void internal_remove_poll(H3270 *session, void *id)
266 267
267 lib3270_free(ip); 268 lib3270_free(ip);
268 session->inputs_changed = 1; 269 session->inputs_changed = 1;
  270 + */
269 } 271 }
270 272
271 static void internal_set_poll_state(H3270 *session, void *id, int enabled) 273 static void internal_set_poll_state(H3270 *session, void *id, int enabled)
272 { 274 {
273 input_t *ip; 275 input_t *ip;
274 276
275 - for (ip = session->inputs; ip != (input_t *) NULL; ip = (input_t *) ip->next) 277 + for (ip = (input_t *) session->input.list.first; ip; ip = (input_t *) ip->next)
276 { 278 {
277 if (ip == (input_t *)id) 279 if (ip == (input_t *)id)
278 { 280 {
279 ip->enabled = enabled ? 1 : 0; 281 ip->enabled = enabled ? 1 : 0;
280 - session->inputs_changed = 1; 282 + session->input.changed = 1;
281 break; 283 break;
282 } 284 }
283 285
@@ -303,10 +305,9 @@ LIB3270_EXPORT void lib3270_set_poll_state(H3270 *session, void *id, int enabled @@ -303,10 +305,9 @@ LIB3270_EXPORT void lib3270_set_poll_state(H3270 *session, void *id, int enabled
303 305
304 LIB3270_EXPORT void lib3270_remove_poll_fd(H3270 *session, int fd) 306 LIB3270_EXPORT void lib3270_remove_poll_fd(H3270 *session, int fd)
305 { 307 {
306 -  
307 input_t *ip; 308 input_t *ip;
308 309
309 - for (ip = session->inputs; ip != (input_t *)NULL; ip = ip->next) 310 + for (ip = (input_t *) session->input.list.first; ip; ip = ip->next)
310 { 311 {
311 if(ip->fd == fd) 312 if(ip->fd == fd)
312 { 313 {
@@ -321,10 +322,9 @@ LIB3270_EXPORT void lib3270_remove_poll_fd(H3270 *session, int fd) @@ -321,10 +322,9 @@ LIB3270_EXPORT void lib3270_remove_poll_fd(H3270 *session, int fd)
321 322
322 LIB3270_EXPORT void lib3270_update_poll_fd(H3270 *session, int fd, LIB3270_IO_FLAG flag) 323 LIB3270_EXPORT void lib3270_update_poll_fd(H3270 *session, int fd, LIB3270_IO_FLAG flag)
323 { 324 {
324 -  
325 input_t *ip; 325 input_t *ip;
326 326
327 - for (ip = session->inputs; ip != (input_t *)NULL; ip = (input_t *) ip->next) 327 + for (ip = (input_t *) session->input.list.first; ip; ip = ip->next)
328 { 328 {
329 if(ip->fd == fd) 329 if(ip->fd == fd)
330 { 330 {
src/core/linux/event_dispatcher.c
@@ -63,7 +63,7 @@ int lib3270_default_event_dispatcher(H3270 *hSession, int block) @@ -63,7 +63,7 @@ int lib3270_default_event_dispatcher(H3270 *hSession, int block)
63 63
64 retry: 64 retry:
65 65
66 - hSession->inputs_changed = 0; 66 + hSession->input.changed = 0;
67 67
68 // If we've processed any input, then don't block again. 68 // If we've processed any input, then don't block again.
69 if(processed_any) 69 if(processed_any)
@@ -75,7 +75,7 @@ retry: @@ -75,7 +75,7 @@ retry:
75 FD_ZERO(&wfds); 75 FD_ZERO(&wfds);
76 FD_ZERO(&xfds); 76 FD_ZERO(&xfds);
77 77
78 - for (ip = hSession->inputs; ip != (input_t *)NULL; ip = (input_t *) ip->next) 78 + for (ip = (input_t *) hSession->input.list.first; ip != (input_t *)NULL; ip = (input_t *) ip->next)
79 { 79 {
80 if(!ip->enabled) 80 if(!ip->enabled)
81 { 81 {
@@ -147,13 +147,13 @@ retry: @@ -147,13 +147,13 @@ retry:
147 } 147 }
148 else 148 else
149 { 149 {
150 - for (ip = hSession->inputs; ip != (input_t *) NULL; ip = (input_t *) ip->next) 150 + for (ip = (input_t *) hSession->input.list.first; ip != (input_t *) NULL; ip = (input_t *) ip->next)
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)(ip->session,ip->fd,LIB3270_IO_FLAG_READ,ip->userdata);
155 processed_any = True; 155 processed_any = True;
156 - if (hSession->inputs_changed) 156 + if (hSession->input.changed)
157 goto retry; 157 goto retry;
158 } 158 }
159 159
@@ -161,7 +161,7 @@ retry: @@ -161,7 +161,7 @@ retry:
161 { 161 {
162 (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_WRITE,ip->userdata); 162 (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_WRITE,ip->userdata);
163 processed_any = True; 163 processed_any = True;
164 - if (hSession->inputs_changed) 164 + if (hSession->input.changed)
165 goto retry; 165 goto retry;
166 } 166 }
167 167
@@ -169,7 +169,7 @@ retry: @@ -169,7 +169,7 @@ retry:
169 { 169 {
170 (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_EXCEPTION,ip->userdata); 170 (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_EXCEPTION,ip->userdata);
171 processed_any = True; 171 processed_any = True;
172 - if (hSession->inputs_changed) 172 + if (hSession->input.changed)
173 goto retry; 173 goto retry;
174 } 174 }
175 } 175 }
@@ -195,7 +195,7 @@ retry: @@ -195,7 +195,7 @@ retry:
195 } 195 }
196 } 196 }
197 197
198 - if (hSession->inputs_changed) 198 + if (hSession->input.changed)
199 goto retry; 199 goto retry;
200 200
201 return processed_any; 201 return processed_any;
src/core/session.c
@@ -142,12 +142,7 @@ void lib3270_session_free(H3270 *h) @@ -142,12 +142,7 @@ void lib3270_session_free(H3270 *h)
142 } 142 }
143 143
144 // Release inputs; 144 // Release inputs;
145 - while(h->inputs)  
146 - {  
147 - input_t *ip = h->inputs;  
148 - h->inputs = (input_t *) ip->next;  
149 - lib3270_free(ip);  
150 - } 145 + lib3270_linked_list_free(&h->input.list);
151 146
152 trace("Releasing session %p",h); 147 trace("Releasing session %p",h);
153 lib3270_free(h); 148 lib3270_free(h);
src/include/lib3270-internals.h
@@ -310,14 +310,14 @@ typedef struct timeout @@ -310,14 +310,14 @@ typedef struct timeout
310 */ 310 */
311 typedef struct _input_t 311 typedef struct _input_t
312 { 312 {
313 - unsigned char enabled;  
314 - struct _input_t * next;  
315 - H3270 * session;  
316 - int fd;  
317 - LIB3270_IO_FLAG flag;  
318 - void * userdata; 313 + LIB3270_LINKED_LIST_HEAD;
  314 +
  315 + unsigned char enabled;
  316 + H3270 * session;
  317 + int fd;
  318 + LIB3270_IO_FLAG flag;
319 319
320 - void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); 320 + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *);
321 321
322 } input_t; 322 } input_t;
323 323
@@ -685,8 +685,12 @@ struct _h3270 @@ -685,8 +685,12 @@ struct _h3270
685 #endif // HAVE_LIBSSL 685 #endif // HAVE_LIBSSL
686 686
687 timeout_t * timeouts; 687 timeout_t * timeouts;
688 - input_t * inputs;  
689 - int inputs_changed : 1; 688 +
  689 + struct
  690 + {
  691 + struct lib3270_linked_list_head list;
  692 + int changed : 1;
  693 + } input;
690 694
691 // Trace methods. 695 // Trace methods.
692 struct 696 struct