diff --git a/src/include/lib3270.h b/src/include/lib3270.h index e3c5b19..7d178a5 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -657,26 +657,18 @@ void * (*AddTimeOut)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); void (*RemoveTimeOut)(void *timer); -#ifdef WIN32 - void * (*AddInput)(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); - void * (*AddOutput)(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); -#else void * (*AddInput)(int source, H3270 *session, void (*fn)(H3270 *session)); void * (*AddOutput)(int source, H3270 *session, void (*fn)(H3270 *session)); -#endif // WIN32 + void (*RemoveSource)(void *id); -#ifdef WIN32 - void * (*AddExcept)(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); -#else void * (*AddExcept)(int source, H3270 *session, void (*fn)(H3270 *session)); -#endif - int (*callthread)(int(*callback)(H3270 *, void *), H3270 *session, void *parm); + int (*callthread)(int(*callback)(H3270 *, void *), H3270 *session, void *parm); - int (*Wait)(H3270 *hSession, int seconds); - int (*event_dispatcher)(H3270 *hSession, int wait); - void (*ring_bell)(H3270 *); + int (*Wait)(H3270 *hSession, int seconds); + int (*event_dispatcher)(H3270 *hSession, int wait); + void (*ring_bell)(H3270 *); }; diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index 62495f6..f96e125 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -76,14 +76,11 @@ struct _h3270 { - unsigned short sz; /**< Struct size */ + unsigned short sz; /**< Struct size */ // Connection info - int sock; /**< Network socket */ - #ifdef _WIN32 - HANDLE sockEvent; /**< Event semaphore */ - #endif // WIN32 - LIB3270_CSTATE cstate; /**< Connection state */ + int sock; /**< Network socket */ + LIB3270_CSTATE cstate; /**< Connection state */ // flags LIB3270_OPTION options; /**< Session options */ diff --git a/src/lib3270/connect.c b/src/lib3270/connect.c index 5ba6242..085c394 100644 --- a/src/lib3270/connect.c +++ b/src/lib3270/connect.c @@ -113,15 +113,10 @@ static void net_connected(H3270 *hSession) return; } -#ifdef _WIN32 - hSession->ns_exception_id = AddExcept(hSession->sockEvent, hSession, net_exception); - hSession->ns_read_id = AddInput(hSession->sockEvent, hSession, net_input); -#else hSession->ns_exception_id = AddExcept(hSession->sock, hSession, net_exception); hSession->ns_read_id = AddInput(hSession->sock, hSession, net_input); -#endif // WIN32 - hSession->excepting = 1; - hSession->reading = 1; + hSession->excepting = 1; + hSession->reading = 1; #if defined(HAVE_LIBSSL) if(hSession->ssl_con && hSession->secure == LIB3270_SSL_UNDEFINED) @@ -348,34 +343,6 @@ static void net_connected(H3270 *hSession) #ifdef WIN32 - if(hSession->sockEvent == NULL) - { - char ename[256]; - - snprintf(ename, 255, "%s-%d", PACKAGE_NAME, getpid()); - - hSession->sockEvent = CreateEvent(NULL, TRUE, FALSE, ename); - if(hSession->sockEvent == NULL) - { - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_CRITICAL, - N_( "Network startup error" ), - N_( "Cannot create socket event" ), - "%s", lib3270_win32_strerror(GetLastError()) ); - _exit(1); - } - } - - if (WSAEventSelect(hSession->sock, hSession->sockEvent, FD_READ | FD_CONNECT | FD_CLOSE) != 0) - { - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_CRITICAL, - N_( "Network startup error" ), - N_( "WSAEventSelect failed" ), - "%s", lib3270_win32_strerror(GetLastError()) ); - _exit(1); - } - WSASetLastError(0); u_long iMode=1; trace("sock=%d",hSession->sock); @@ -523,12 +490,7 @@ static void net_connected(H3270 *hSession) hSession->cstate = LIB3270_PENDING; lib3270_st_changed(hSession, LIB3270_STATE_HALF_CONNECT, True); -#ifdef _WIN32 - trace("Sockevent=%08lx callback=%p",hSession->sockEvent,net_connected); - hSession->ns_write_id = AddOutput(hSession->sockEvent, hSession, net_connected); -#else hSession->ns_write_id = AddOutput(hSession->sock, hSession, net_connected); -#endif // WIN32 trace("%s: Connection in progress",__FUNCTION__); diff --git a/src/lib3270/iocalls.c b/src/lib3270/iocalls.c index 2360651..31956de 100644 --- a/src/lib3270/iocalls.c +++ b/src/lib3270/iocalls.c @@ -51,15 +51,9 @@ 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)); -#ifdef WIN32 - static void * internal_add_input(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); - static void * internal_add_output(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); - static void * internal_add_except(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); -#else - 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)); -#endif // WIN32 +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); @@ -78,16 +72,6 @@ static void internal_ring_bell(H3270 *); static void (*remove_source)(void *id) = internal_remove_source; -#ifdef WIN32 - static void * (*add_input)(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) - = internal_add_input; - - static void * (*add_output)(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) - = internal_add_output; - - static void * (*add_except)(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) - = internal_add_except; -#else static void * (*add_input)(int source, H3270 *session, void (*fn)(H3270 *session)) = internal_add_input; @@ -96,7 +80,6 @@ static void internal_ring_bell(H3270 *); static void * (*add_except)(int source, H3270 *session, void (*fn)(H3270 *session)) = internal_add_except; -#endif // WIN32 static int (*callthread)(int(*callback)(H3270 *, void *), H3270 *session, void *parm) = internal_callthread; @@ -131,11 +114,7 @@ static void internal_ring_bell(H3270 *); typedef struct input { struct input *next; -#if defined(_WIN32) - HANDLE source; -#else int source; -#endif // WIN32 int condition; void (*proc)(H3270 *session); H3270 *session; @@ -261,11 +240,7 @@ static void internal_remove_timeout(void * timer) /* Input events. */ -#ifdef WIN32 -static void * internal_add_input(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -#else static void * internal_add_input(int source, H3270 *session, void (*fn)(H3270 *session)) -#endif // WIN32 { input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); @@ -280,11 +255,7 @@ static void * internal_add_input(int source, H3270 *session, void (*fn)(H3270 *s return ip; } -#ifdef WIN32 -static void * internal_add_output(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -#else static void * internal_add_output(int source, H3270 *session, void (*fn)(H3270 *session)) -#endif // WIN32 { input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); @@ -299,13 +270,6 @@ static void * internal_add_output(int source, H3270 *session, void (*fn)(H3270 * return ip; } - -#if defined(_WIN32) -static void * internal_add_except(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -{ - return 0; -} -#else static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 *session)) { input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t)); @@ -322,7 +286,6 @@ static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 * return ip; } -#endif // WIN32 static void internal_remove_source(void *id) { @@ -356,19 +319,19 @@ static void internal_remove_source(void *id) static int internal_event_dispatcher(H3270 *hSession, int block) { #if defined(_WIN32) - HANDLE ha[MAX_HA]; - DWORD events; - DWORD tmo; unsigned long long now; - int i; +// int i; + int maxSock; + DWORD tmo; #else - fd_set rfds, wfds, xfds; int ns; struct timeval now, twait, *tp; int events; #endif + + fd_set rfds, wfds, xfds; + input_t *ip; - struct timeout *t; int processed_any = 0; retry: @@ -379,16 +342,33 @@ retry: if(processed_any) block = 0; - events = 0; - #if defined(_WIN32) + maxSock = 0; + + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&xfds); + for (ip = inputs; ip != (input_t *)NULL; ip = ip->next) { if ((unsigned long)ip->condition & InputReadMask) - ha[events++] = ip->source; + { + FD_SET(ip->source, &rfds); + maxSock = max(ip->source,maxSock); + } + if ((unsigned long)ip->condition & InputWriteMask) - ha[events++] = ip->source; + { + FD_SET(ip->source, &wfds); + maxSock = max(ip->source,maxSock); + } + + if ((unsigned long)ip->condition & InputExceptMask) + { + FD_SET(ip->source, &xfds); + maxSock = max(ip->source,maxSock); + } } if (block) @@ -404,19 +384,67 @@ retry: else { // Block for 1 second (at maximal) - tmo = 1; + tmo = 1000; } } - else if (!events) + else { - // No block & no events, return - return processed_any; + tmo = 1000; } - else + + if(maxSock) { - tmo = 1; + struct timeval tm; + + tm.tv_sec = 0; + tm.tv_usec = tmo; + + int ns = select(maxSock+1, &rfds, &wfds, &xfds, &tm); + + if (ns < 0 && errno != EINTR) + { + lib3270_popup_dialog( hSession, + LIB3270_NOTIFY_ERROR, + _( "Network error" ), + _( "Select() failed when processing for events." ), + lib3270_win32_strerror(WSAGetLastError())); + } + else + { + for (ip = inputs; ip != (input_t *) NULL; ip = ip->next) + { + if (((unsigned long)ip->condition & InputReadMask) && FD_ISSET(ip->source, &rfds)) + { + (*ip->proc)(ip->session); + processed_any = True; + if (inputs_changed) + goto retry; + } + + if (((unsigned long)ip->condition & InputWriteMask) && FD_ISSET(ip->source, &wfds)) + { + (*ip->proc)(ip->session); + processed_any = True; + if (inputs_changed) + goto retry; + } + + if (((unsigned long)ip->condition & InputExceptMask) && FD_ISSET(ip->source, &xfds)) + { + (*ip->proc)(ip->session); + processed_any = True; + if (inputs_changed) + goto retry; + } + } + } + } + else if(block) + { + Sleep(tmo); } +/* if(events) { DWORD ret = WaitForMultipleObjects(events, ha, FALSE, tmo); @@ -451,9 +479,12 @@ retry: { Sleep(100); } +*/ #else + events = 0; + FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); @@ -558,6 +589,7 @@ retry: if (timeouts != TN) { #if defined(_WIN32) + struct timeout *t; ms_ts(&now); #else (void) gettimeofday(&now, (void *)NULL); @@ -630,31 +662,19 @@ void RemoveTimeOut(void * timer) return remove_timeout(timer); } -#ifdef WIN32 -void * AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -#else void * AddInput(int source, H3270 *session, void (*fn)(H3270 *session)) -#endif // WIN32 { CHECK_SESSION_HANDLE(session); return add_input(source,session,fn); } -#ifdef WIN32 -void * AddOutput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -#else void * AddOutput(int source, H3270 *session, void (*fn)(H3270 *session)) -#endif // WIN32 { CHECK_SESSION_HANDLE(session); return add_output(source,session,fn); } -#ifdef WIN32 -void * AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -#else void * AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) -#endif // WIN32 { CHECK_SESSION_HANDLE(session); return add_except(source,session,fn); @@ -673,19 +693,11 @@ void x_except_on(H3270 *h) if(h->reading) RemoveSource(h->ns_read_id); -#ifdef WIN32 - h->ns_exception_id = AddExcept(h->sockEvent, h, net_exception); - h->excepting = 1; - - if(h->reading) - h->ns_read_id = AddInput(h->sockEvent, h, net_input); -#else 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); -#endif // WIN32 } void remove_input_calls(H3270 *session) diff --git a/src/lib3270/session.c b/src/lib3270/session.c index 7ddde39..bc77e2f 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -310,11 +310,6 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char for(f=0;f<4;f++) hSession->csd[f] = hSession->saved_csd[f] = LIB3270_ANSI_CSD_US; -#ifdef _WIN32 - hSession->sockEvent = NULL; -#endif // _WIN32 - - // Initialize toggles initialize_toggles(hSession); diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index d3052d5..829f0ee 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -1002,10 +1002,6 @@ void net_input(H3270 *hSession) hSession->ansi_data = 0; #endif -#if defined(_WIN32) - ResetEvent(hSession->sockEvent); -#endif - #if defined(HAVE_LIBSSL) if (hSession->ssl_con != NULL) nr = SSL_read(hSession->ssl_con, (char *) buffer, BUFSZ); diff --git a/src/lib3270/testprogram.c b/src/lib3270/testprogram.c index d7ca4b0..055347b 100644 --- a/src/lib3270/testprogram.c +++ b/src/lib3270/testprogram.c @@ -36,11 +36,8 @@ int main(int numpar, char *param[]) // pthread_create(&thread, NULL, mainloop, NULL); // pthread_detach(thread); -// rc = lib3270_connect_host(h, "fandezhi.efglobe.com", "telnet", LIB3270_CONNECT_OPTION_WAIT); -// rc = lib3270_connect_host(h, "127.0.0.1", "9090", LIB3270_CONNECT_OPTION_WAIT); - -// lib3270_set_host_url(h,"tn3270://fandezhi.efglobe.com:9090?lu=default"); lib3270_set_url(h,"tn3270://fandezhi.efglobe.com"); + rc = lib3270_connect(h,1); printf("\nConnect exits with rc=%d\n",rc); diff --git a/src/lib3270/utilc.h b/src/lib3270/utilc.h index 1f66e35..3a268be 100644 --- a/src/lib3270/utilc.h +++ b/src/lib3270/utilc.h @@ -36,15 +36,10 @@ LIB3270_INTERNAL char *xs_buffer(const char *fmt, ...) printflike(1, 2); LIB3270_INTERNAL void xs_error(const char *fmt, ...) printflike(1, 2); LIB3270_INTERNAL void xs_warning(const char *fmt, ...) printflike(1, 2); -#ifdef WIN32 - LIB3270_INTERNAL void * AddInput(HANDLE, H3270 *session, void (*fn)(H3270 *session)); - LIB3270_INTERNAL void * AddOutput(HANDLE, H3270 *session, void (*fn)(H3270 *session)); - LIB3270_INTERNAL void * AddExcept(HANDLE, H3270 *session, void (*fn)(H3270 *session)); -#else - LIB3270_INTERNAL void * AddInput(int, H3270 *session, void (*fn)(H3270 *session)); - LIB3270_INTERNAL void * AddOutput(int, H3270 *session, void (*fn)(H3270 *session)); - LIB3270_INTERNAL void * AddExcept(int, H3270 *session, void (*fn)(H3270 *session)); -#endif // WIN32 +LIB3270_INTERNAL void * AddInput(int, H3270 *session, void (*fn)(H3270 *session)); +LIB3270_INTERNAL void * AddOutput(int, H3270 *session, void (*fn)(H3270 *session)); +LIB3270_INTERNAL void * AddExcept(int, H3270 *session, void (*fn)(H3270 *session)); + LIB3270_INTERNAL void RemoveSource(void *); LIB3270_INTERNAL void * AddTimeOut(unsigned long msec, H3270 *session, void (*fn)(H3270 *session)); LIB3270_INTERNAL void RemoveTimeOut(void *cookie); diff --git a/src/plugins/dbus3270/iocallback.c b/src/plugins/dbus3270/iocallback.c index 9dd1a3c..5337022 100644 --- a/src/plugins/dbus3270/iocallback.c +++ b/src/plugins/dbus3270/iocallback.c @@ -46,13 +46,8 @@ static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm); static void static_RemoveSource(void *id); -#ifdef WIN32 -static void * static_AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); -static void * static_AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); -#else static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)); static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)); -#endif // WIN32 static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); static void static_RemoveTimeOut(void * timer); diff --git a/src/plugins/hllapi/pluginmain.c b/src/plugins/hllapi/pluginmain.c index 9e5758a..f4afe9e 100644 --- a/src/plugins/hllapi/pluginmain.c +++ b/src/plugins/hllapi/pluginmain.c @@ -201,7 +201,7 @@ break; case HLLAPI_PACKET_SET_HOST: - send_result(source,lib3270_set_host( lib3270_get_default_session_handle(), + send_result(source,lib3270_set_url( lib3270_get_default_session_handle(), ((struct hllapi_packet_text *) source->buffer)->text) != NULL); break; diff --git a/src/pw3270/v3270/iocallback.c b/src/pw3270/v3270/iocallback.c index d053738..dba7235 100644 --- a/src/pw3270/v3270/iocallback.c +++ b/src/pw3270/v3270/iocallback.c @@ -46,13 +46,8 @@ static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm); static void static_RemoveSource(void *id); -#ifdef WIN32 -static void * static_AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); -static void * static_AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session)); -#else static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)); static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)); -#endif // WIN32 static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); static void static_RemoveTimeOut(void * timer); @@ -71,11 +66,7 @@ static gboolean IO_closure(gpointer data); { GSource gsrc; GPollFD poll; -#if defined(_WIN32) - HANDLE source; -#else int source; -#endif // WIN32 void (*fn)(H3270 *session); H3270 *session; } IO_Source; @@ -99,11 +90,7 @@ static gboolean IO_closure(gpointer data); /*---[ Implement ]-----------------------------------------------------------------------------------------*/ -#ifdef WIN32 -static void * AddSource(HANDLE source, H3270 *session, gushort events, void (*fn)(H3270 *session)) -#else static void * AddSource(int source, H3270 *session, gushort events, void (*fn)(H3270 *session)) -#endif // WIN32 { IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); @@ -119,21 +106,13 @@ static void * AddSource(int source, H3270 *session, gushort events, void (*fn)(H return src; } -#ifdef WIN32 -static void * static_AddOutput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -#else static void * static_AddOutput(int source, H3270 *session, void (*fn)(H3270 *session)) -#endif // WIN32 { return AddSource(source,session,G_IO_OUT|G_IO_HUP|G_IO_ERR,fn); } -#ifdef WIN32 -static void * static_AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -#else static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)) -#endif // WIN32 { return AddSource(source,session,G_IO_IN|G_IO_HUP|G_IO_ERR,fn); } @@ -144,17 +123,10 @@ static void static_RemoveSource(void *id) g_source_destroy((GSource *) id); } -#if defined(WIN32) -static void * static_AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -{ - return 0; -} -#else static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) { return AddSource(source,session,G_IO_HUP|G_IO_ERR,fn); } -#endif // WIN32 static gboolean do_timer(TIMER *t) { @@ -208,12 +180,11 @@ static gboolean IO_check(GSource *source) * function was called, so the source should be checked again here. * */ -#if defined(_WIN32) /*[*/ +#ifdef _WIN32 - if(WaitForSingleObject(((IO_Source *) source)->source,0) == WAIT_OBJECT_0) - return TRUE; + #error AQUI -#else /*][*/ +#else struct pollfd fds; @@ -225,7 +196,7 @@ static gboolean IO_check(GSource *source) if(poll(&fds,1,0) > 0) return TRUE; -#endif /*]*/ +#endif // _WIN32 return FALSE; } -- libgit2 0.21.2