diff --git a/connect.c b/connect.c index c3e2801..a78413e 100644 --- a/connect.c +++ b/connect.c @@ -76,13 +76,14 @@ /*---[ Implement ]-------------------------------------------------------------------------------*/ -static void net_connected(H3270 *hSession) +//static void net_connected(H3270 *hSession) +static void net_connected(H3270 *hSession, LIB3270_IO_FLAG flag, void *dunno) { int err; socklen_t len = sizeof(err); trace("%s",__FUNCTION__); - RemoveSource(hSession->ns_write_id); + lib3270_remove_poll(hSession->ns_write_id); hSession->ns_write_id = NULL; if(getsockopt(hSession->sock, SOL_SOCKET, SO_ERROR, (char *) &err, &len) < 0) @@ -120,8 +121,12 @@ static void net_connected(H3270 *hSession) return; } - hSession->ns_exception_id = AddExcept(hSession->sock, hSession, net_exception); - hSession->ns_read_id = AddInput(hSession->sock, hSession, net_input); +// hSession->ns_exception_id = AddExcept(hSession->sock, hSession, net_exception); +// hSession->ns_read_id = AddInput(hSession->sock, hSession, net_input); + + hSession->ns_exception_id = lib3270_add_poll_fd(hSession,hSession->sock,LIB3270_IO_FLAG_EXCEPTION,net_exception,0); + hSession->ns_read_id = lib3270_add_poll_fd(hSession,hSession->sock,LIB3270_IO_FLAG_READ,net_input,0); + hSession->excepting = 1; hSession->reading = 1; @@ -498,7 +503,8 @@ static void net_connected(H3270 *hSession) hSession->cstate = LIB3270_PENDING; lib3270_st_changed(hSession, LIB3270_STATE_HALF_CONNECT, True); - hSession->ns_write_id = AddOutput(hSession->sock, hSession, net_connected); + hSession->ns_write_id = lib3270_add_poll_fd(hSession,hSession->sock,LIB3270_IO_FLAG_WRITE,net_connected,0); + // hSession->ns_write_id = AddOutput(hSession->sock, hSession, net_connected); trace("%s: Connection in progress",__FUNCTION__); diff --git a/iocalls.c b/iocalls.c index f127390..60100b2 100644 --- a/iocalls.c +++ b/iocalls.c @@ -37,9 +37,6 @@ #include "utilc.h" #define MILLION 1000000L -#define InputReadMask 0x1 -#define InputExceptMask 0x2 -#define InputWriteMask 0x4 #if defined(_WIN32) #define MAX_HA 256 @@ -47,18 +44,25 @@ /*---[ Standard calls ]-------------------------------------------------------------------------------------*/ -static void internal_remove_timeout(void *timer); -static void internal_remove_source(void *id); -static void * internal_add_timeout(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); +// Timeout calls +static void internal_remove_timeout(void *timer); +static void * internal_add_timeout(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); +static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata ); +static void internal_remove_poll(void *id); + + +/* +// fdcalls +static void internal_remove_source(void *id); static void * internal_add_input(int source, H3270 *session, void (*fn)(H3270 *session)); static void * internal_add_output(int source, H3270 *session, void (*fn)(H3270 *session)); static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 *session)); +*/ -// static int internal_callthread(int(*callback)(H3270 *, void *), H3270 *session, void *parm); -static int internal_wait(H3270 *hSession, int seconds); +static int internal_wait(H3270 *hSession, int seconds); -static int internal_event_dispatcher(H3270 *hSession, int block); +static int internal_event_dispatcher(H3270 *hSession, int block); static void internal_ring_bell(H3270 *); /*---[ Active callbacks ]-----------------------------------------------------------------------------------*/ @@ -69,19 +73,13 @@ static void internal_ring_bell(H3270 *); static void (*remove_timeout)(void *timer) = internal_remove_timeout; - static void (*remove_source)(void *id) - = internal_remove_source; - - static void * (*add_input)(int source, H3270 *session, void (*fn)(H3270 *session)) - = internal_add_input; + static void * (*add_poll)(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) + = internal_add_poll; - static void * (*add_output)(int source, H3270 *session, void (*fn)(H3270 *session)) - = internal_add_output; + static void (*remove_poll)(void *id) + = internal_remove_poll; - static void * (*add_except)(int source, H3270 *session, void (*fn)(H3270 *session)) - = internal_add_except; - - static int (*wait)(H3270 *hSession, int seconds) + static int (*wait)(H3270 *hSession, int seconds) = internal_wait; static int (*event_dispatcher)(H3270 *hSession,int wait) @@ -107,23 +105,25 @@ static void internal_ring_bell(H3270 *); #define TN (timeout_t *)NULL - /* Input events. */ +/* I/O events. */ typedef struct input { - struct input *next; - int source; - int condition; - void (*proc)(H3270 *session); - H3270 *session; -} input_t; + struct input * next; + H3270 * session; + int fd; + LIB3270_IO_FLAG flag; + void * userdata; + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); + +} input_t; /*---[ Statics ]--------------------------------------------------------------------------------------------*/ static timeout_t * timeouts = NULL; static input_t * inputs = NULL; - static Boolean inputs_changed = False; + static Boolean inputs_changed = False; /*---[ Implement ]------------------------------------------------------------------------------------------*/ @@ -235,56 +235,25 @@ static void internal_remove_timeout(void * timer) } } -/* Input events. */ +/* I/O events. */ -static void * internal_add_input(int source, H3270 *session, void (*fn)(H3270 *session)) +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)); - ip->source = source; - ip->condition = InputReadMask; - ip->proc = fn; - ip->session = session; - ip->next = inputs; - inputs = ip; - inputs_changed = True; - - return ip; -} - -static void * internal_add_output(int source, H3270 *session, void (*fn)(H3270 *session)) -{ - input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); + ip->session = session; + ip->fd = fd; + ip->flag = flag; + ip->userdata = userdata; + ip->call = call; - ip->source = source; - ip->condition = InputWriteMask; - ip->proc = fn; - ip->session = session; - ip->next = inputs; inputs = ip; inputs_changed = True; return ip; } -static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 *session)) -{ - input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); - - ip->source = source; - ip->condition = InputExceptMask; - ip->proc = fn; - ip->session = session; - ip->next = inputs; - inputs = ip; - inputs_changed = True; - - trace("%s session=%p proc=%p handle=%p",__FUNCTION__,ip->session,ip->proc,ip); - - return ip; -} - -static void internal_remove_source(void *id) +static void internal_remove_poll(void *id) { input_t *ip; input_t *prev = (input_t *)NULL; @@ -349,22 +318,22 @@ retry: for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) { - if ((unsigned long)ip->condition & InputReadMask) + if(ip->flag & LIB3270_IO_FLAG_READ) { - FD_SET(ip->source, &rfds); - maxSock = max(ip->source,maxSock); + FD_SET(ip->fd, &rfds); + maxSock = max(ip->fd,maxSock); } - if ((unsigned long)ip->condition & InputWriteMask) + if(ip->flag & LIB3270_IO_FLAG_WRITE) { - FD_SET(ip->source, &wfds); - maxSock = max(ip->source,maxSock); + FD_SET(ip->fd, &wfds); + maxSock = max(ip->fd,maxSock); } - if ((unsigned long)ip->condition & InputExceptMask) + if(ip->flag & LIB3270_IO_FLAG_EXCEPTION) { - FD_SET(ip->source, &xfds); - maxSock = max(ip->source,maxSock); + FD_SET(ip->fd, &xfds); + maxSock = max(ip->fd,maxSock); } } @@ -410,7 +379,7 @@ retry: { for (ip = inputs; ip != (input_t *) NULL; ip = ip->next) { - if (((unsigned long)ip->condition & InputReadMask) && FD_ISSET(ip->source, &rfds)) + if((ip->flag & LIB3270_IO_FLAG_READ) && FD_ISSET(ip->fd, &rfds)) { (*ip->proc)(ip->session); processed_any = True; @@ -418,7 +387,7 @@ retry: goto retry; } - if (((unsigned long)ip->condition & InputWriteMask) && FD_ISSET(ip->source, &wfds)) + if ((ip->flag & LIB3270_IO_FLAG_WRITE) && FD_ISSET(ip->fd, &wfds)) { (*ip->proc)(ip->session); processed_any = True; @@ -426,7 +395,7 @@ retry: goto retry; } - if (((unsigned long)ip->condition & InputExceptMask) && FD_ISSET(ip->source, &xfds)) + if ((ip->flag & LIB3270_IO_FLAG_EXCEPTION) && FD_ISSET(ip->fd, &xfds)) { (*ip->proc)(ip->session); processed_any = True; @@ -452,21 +421,21 @@ retry: for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) { - if ((unsigned long)ip->condition & InputReadMask) + if(ip->flag & LIB3270_IO_FLAG_READ) { - FD_SET(ip->source, &rfds); + FD_SET(ip->fd, &rfds); events++; } - if ((unsigned long)ip->condition & InputWriteMask) + if(ip->flag & LIB3270_IO_FLAG_WRITE) { - FD_SET(ip->source, &wfds); + FD_SET(ip->fd, &wfds); events++; } - if ((unsigned long)ip->condition & InputExceptMask) + if(ip->flag & LIB3270_IO_FLAG_EXCEPTION) { - FD_SET(ip->source, &xfds); + FD_SET(ip->fd, &xfds); events++; } } @@ -518,25 +487,25 @@ retry: { for (ip = inputs; ip != (input_t *) NULL; ip = ip->next) { - if (((unsigned long)ip->condition & InputReadMask) && FD_ISSET(ip->source, &rfds)) + if((ip->flag & LIB3270_IO_FLAG_READ) && FD_ISSET(ip->fd, &rfds)) { - (*ip->proc)(ip->session); + (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_READ,ip->userdata); processed_any = True; if (inputs_changed) goto retry; } - if (((unsigned long)ip->condition & InputWriteMask) && FD_ISSET(ip->source, &wfds)) + if((ip->flag & LIB3270_IO_FLAG_WRITE) && FD_ISSET(ip->fd, &wfds)) { - (*ip->proc)(ip->session); + (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_WRITE,ip->userdata); processed_any = True; if (inputs_changed) goto retry; } - if (((unsigned long)ip->condition & InputExceptMask) && FD_ISSET(ip->source, &xfds)) + if((ip->flag & LIB3270_IO_FLAG_EXCEPTION) && FD_ISSET(ip->fd, &xfds)) { - (*ip->proc)(ip->session); + (*ip->call)(ip->session,ip->fd,LIB3270_IO_FLAG_EXCEPTION,ip->userdata); processed_any = True; if (inputs_changed) goto retry; @@ -619,6 +588,7 @@ void RemoveTimeOut(void * timer) return remove_timeout(timer); } +/* void * AddInput(int source, H3270 *session, void (*fn)(H3270 *session)) { CHECK_SESSION_HANDLE(session); @@ -641,6 +611,7 @@ void RemoveSource(void * id) { remove_source(id); } +*/ void x_except_on(H3270 *h) { @@ -648,32 +619,36 @@ void x_except_on(H3270 *h) return; if(h->reading) - RemoveSource(h->ns_read_id); + lib3270_remove_poll(h->ns_read_id); + + h->ns_exception_id = lib3270_add_poll_fd(h,h->sock,LIB3270_IO_FLAG_EXCEPTION,net_exception,0); +// h->ns_exception_id = AddExcept(h->sock, h, net_exception); - h->ns_exception_id = AddExcept(h->sock, h, net_exception); h->excepting = 1; if(h->reading) - h->ns_read_id = AddInput(h->sock, h, net_input); + h->ns_read_id = lib3270_add_poll_fd(h,h->sock,LIB3270_IO_FLAG_READ,net_input,0); + +// h->ns_read_id = AddInput(h->sock, h, net_input); } void remove_input_calls(H3270 *session) { if(session->ns_read_id) { - RemoveSource(session->ns_read_id); + lib3270_remove_poll(session->ns_read_id); session->ns_read_id = NULL; session->reading = 0; } if(session->ns_exception_id) { - RemoveSource(session->ns_exception_id); + lib3270_remove_poll(session->ns_exception_id); session->ns_exception_id = NULL; session->excepting = 0; } if(session->ns_write_id) { - RemoveSource(session->ns_write_id); + lib3270_remove_poll(session->ns_write_id); session->ns_write_id = NULL; session->writing = 0; } @@ -689,6 +664,7 @@ LIB3270_EXPORT void lib3270_register_time_handlers(void * (*add)(unsigned long i } +/* LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk) { if(!cbk) @@ -723,6 +699,7 @@ LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk return 0; } +*/ LIB3270_EXPORT void lib3270_iterate(int block) { event_dispatcher(NULL,block); diff --git a/telnet.c b/telnet.c index 3a5c760..fe118b2 100644 --- a/telnet.c +++ b/telnet.c @@ -909,7 +909,7 @@ LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession) if(hSession->ns_write_id) { - RemoveSource(hSession->ns_write_id); + lib3270_remove_poll(hSession->ns_write_id); hSession->ns_write_id = 0; } @@ -988,7 +988,7 @@ LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned * @param hSession Session handle * */ -void net_input(H3270 *hSession) +void net_input(H3270 *hSession, LIB3270_IO_FLAG flag, void *dunno) { // register unsigned char * cp; int nr; @@ -1950,7 +1950,7 @@ process_eor(H3270 *hSession) * net_exception * Called when there is an exceptional condition on the socket. */ -void net_exception(H3270 *session) +void net_exception(H3270 *session, LIB3270_IO_FLAG flag, void *dunno) { CHECK_SESSION_HANDLE(session); @@ -1961,7 +1961,7 @@ void net_exception(H3270 *session) if(session->excepting) { - RemoveSource(session->ns_exception_id); + lib3270_remove_poll(session->ns_exception_id); session->ns_exception_id = NULL; session->excepting = 0; } diff --git a/telnetc.h b/telnetc.h index ed4942a..e7fa430 100644 --- a/telnetc.h +++ b/telnetc.h @@ -30,34 +30,20 @@ struct ctl_char { }; LIB3270_INTERNAL void net_abort(H3270 *hSession); -// LIB3270_INTERNAL Boolean net_add_dummy_tn3270e(H3270 *hSession); LIB3270_INTERNAL void net_add_eor(unsigned char *buf, int len); LIB3270_INTERNAL void net_break(H3270 *hSession); -// LIB3270_INTERNAL void net_charmode(H3270 *hSession); LIB3270_INTERNAL int net_connect(H3270 *session, const char *, char *, Boolean, Boolean *, Boolean *); LIB3270_INTERNAL void net_disconnect(H3270 *session); -LIB3270_INTERNAL void net_exception(H3270 *session); -// LIB3270_INTERNAL void net_hexansi_out(unsigned char *buf, int len); -LIB3270_INTERNAL void net_input(H3270 *session); +LIB3270_INTERNAL void net_exception(H3270 *session, LIB3270_IO_FLAG flag, void *dunno); +LIB3270_INTERNAL void net_input(H3270 *session, LIB3270_IO_FLAG flag, void *dunno); LIB3270_INTERNAL void net_interrupt(H3270 *hSession); -// LIB3270_INTERNAL void net_linemode(void); -// LIB3270_INTERNAL struct ctl_char *net_linemode_chars(void); LIB3270_INTERNAL void net_output(H3270 *hSession); -//LIB3270_INTERNAL const char *net_query_bind_plu_name(void); -//LIB3270_INTERNAL const char *net_query_connection_state(void); -//LIB3270_INTERNAL const char *net_query_host(void); -//LIB3270_INTERNAL const char *net_query_lu_name(void); LIB3270_INTERNAL void net_sendc(H3270 *hSession, char c); LIB3270_INTERNAL void net_sends(H3270 *hSession, const char *s); LIB3270_INTERNAL void net_send_erase(H3270 *hSession); LIB3270_INTERNAL void net_send_kill(H3270 *hSession); LIB3270_INTERNAL void net_send_werase(H3270 *hSession); -// LIB3270_INTERNAL Boolean net_snap_options(void); LIB3270_INTERNAL void space3270out(H3270 *hSession, int n); -// LIB3270_INTERNAL const char *tn3270e_current_opts(void); -// LIB3270_INTERNAL char *net_proxy_type(void); -//LIB3270_INTERNAL char *net_proxy_host(void); -// LIB3270_INTERNAL char *net_proxy_port(void); #if defined(X3270_TRACE) LIB3270_INTERNAL void trace_netdata(H3270 *hSession, char direction, unsigned const char *buf, int len); -- libgit2 0.21.2