From a15d2dbb33ff5450d857d0419ee62a06d87a43c0 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 14 Oct 2019 10:36:58 -0300 Subject: [PATCH] Updating input list to use the new chained list managers. --- src/core/iocalls.c | 24 ++++++++++++------------ src/core/linux/event_dispatcher.c | 14 +++++++------- src/core/session.c | 7 +------ src/include/lib3270-internals.h | 22 +++++++++++++--------- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/core/iocalls.c b/src/core/iocalls.c index 4e64eb0..3bd790f 100644 --- a/src/core/iocalls.c +++ b/src/core/iocalls.c @@ -223,25 +223,26 @@ static void internal_remove_timer(H3270 *session, void * timer) static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata ) { - input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); + input_t *ip = (input_t *) lib3270_linked_list_append_node(&session->input.list,sizeof(input_t), userdata); ip->session = session; ip->enabled = 1; ip->fd = fd; ip->flag = flag; - ip->userdata = userdata; ip->call = call; - ip->next = (input_t *) session->inputs; - - session->inputs = ip; - session->inputs_changed = 1; + session->input.changed = 1; return ip; } static void internal_remove_poll(H3270 *session, void *id) { + lib3270_linked_list_delete_node(&session->input.list,id); + + session->input.changed = 1; + + /* input_t *ip; input_t *prev = (input_t *)NULL; @@ -266,18 +267,19 @@ static void internal_remove_poll(H3270 *session, void *id) lib3270_free(ip); session->inputs_changed = 1; + */ } static void internal_set_poll_state(H3270 *session, void *id, int enabled) { input_t *ip; - for (ip = session->inputs; ip != (input_t *) NULL; ip = (input_t *) ip->next) + for (ip = (input_t *) session->input.list.first; ip; ip = (input_t *) ip->next) { if (ip == (input_t *)id) { ip->enabled = enabled ? 1 : 0; - session->inputs_changed = 1; + session->input.changed = 1; break; } @@ -303,10 +305,9 @@ LIB3270_EXPORT void lib3270_set_poll_state(H3270 *session, void *id, int enabled LIB3270_EXPORT void lib3270_remove_poll_fd(H3270 *session, int fd) { - input_t *ip; - for (ip = session->inputs; ip != (input_t *)NULL; ip = ip->next) + for (ip = (input_t *) session->input.list.first; ip; ip = ip->next) { if(ip->fd == fd) { @@ -321,10 +322,9 @@ LIB3270_EXPORT void lib3270_remove_poll_fd(H3270 *session, int fd) LIB3270_EXPORT void lib3270_update_poll_fd(H3270 *session, int fd, LIB3270_IO_FLAG flag) { - input_t *ip; - for (ip = session->inputs; ip != (input_t *)NULL; ip = (input_t *) ip->next) + for (ip = (input_t *) session->input.list.first; ip; ip = ip->next) { if(ip->fd == fd) { diff --git a/src/core/linux/event_dispatcher.c b/src/core/linux/event_dispatcher.c index 65cab72..d998e1f 100644 --- a/src/core/linux/event_dispatcher.c +++ b/src/core/linux/event_dispatcher.c @@ -63,7 +63,7 @@ int lib3270_default_event_dispatcher(H3270 *hSession, int block) retry: - hSession->inputs_changed = 0; + hSession->input.changed = 0; // If we've processed any input, then don't block again. if(processed_any) @@ -75,7 +75,7 @@ retry: FD_ZERO(&wfds); FD_ZERO(&xfds); - for (ip = hSession->inputs; ip != (input_t *)NULL; ip = (input_t *) ip->next) + for (ip = (input_t *) hSession->input.list.first; ip != (input_t *)NULL; ip = (input_t *) ip->next) { if(!ip->enabled) { @@ -147,13 +147,13 @@ retry: } else { - for (ip = hSession->inputs; ip != (input_t *) NULL; ip = (input_t *) ip->next) + for (ip = (input_t *) hSession->input.list.first; ip != (input_t *) NULL; ip = (input_t *) ip->next) { if((ip->flag & LIB3270_IO_FLAG_READ) && FD_ISSET(ip->fd, &rfds)) { (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_READ,ip->userdata); processed_any = True; - if (hSession->inputs_changed) + if (hSession->input.changed) goto retry; } @@ -161,7 +161,7 @@ retry: { (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_WRITE,ip->userdata); processed_any = True; - if (hSession->inputs_changed) + if (hSession->input.changed) goto retry; } @@ -169,7 +169,7 @@ retry: { (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_EXCEPTION,ip->userdata); processed_any = True; - if (hSession->inputs_changed) + if (hSession->input.changed) goto retry; } } @@ -195,7 +195,7 @@ retry: } } - if (hSession->inputs_changed) + if (hSession->input.changed) goto retry; return processed_any; diff --git a/src/core/session.c b/src/core/session.c index 02af5af..917580d 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -142,12 +142,7 @@ void lib3270_session_free(H3270 *h) } // Release inputs; - while(h->inputs) - { - input_t *ip = h->inputs; - h->inputs = (input_t *) ip->next; - lib3270_free(ip); - } + lib3270_linked_list_free(&h->input.list); trace("Releasing session %p",h); lib3270_free(h); diff --git a/src/include/lib3270-internals.h b/src/include/lib3270-internals.h index 50090a3..705e831 100644 --- a/src/include/lib3270-internals.h +++ b/src/include/lib3270-internals.h @@ -310,14 +310,14 @@ typedef struct timeout */ typedef struct _input_t { - unsigned char enabled; - struct _input_t * next; - H3270 * session; - int fd; - LIB3270_IO_FLAG flag; - void * userdata; + LIB3270_LINKED_LIST_HEAD; + + unsigned char enabled; + H3270 * session; + int fd; + LIB3270_IO_FLAG flag; - void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); } input_t; @@ -685,8 +685,12 @@ struct _h3270 #endif // HAVE_LIBSSL timeout_t * timeouts; - input_t * inputs; - int inputs_changed : 1; + + struct + { + struct lib3270_linked_list_head list; + int changed : 1; + } input; // Trace methods. struct -- libgit2 0.21.2