diff --git a/host.c b/host.c index 2e84cea..a2ff9e8 100644 --- a/host.c +++ b/host.c @@ -547,7 +547,7 @@ static int do_connect(H3270 *hSession, const char *n) /* Attempt contact. */ hSession->ever_3270 = False; - if(net_connect(hSession, chost, port, 0, &resolving,&pending) < 0 && !resolving) + if(net_connect(hSession, chost, port, 0, &resolving,&pending) != 0 && !resolving) { /* Redundantly signal a disconnect. */ host_disconnected(hSession); @@ -572,7 +572,17 @@ static int do_connect(H3270 *hSession, const char *n) // login_macro(ps); /* Prepare Xt for I/O. */ - x_add_input(hSession,hSession->sock); +// x_add_input(hSession); +#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 = True; + hSession->reading = True; /* Set state and tell the world. */ if (pending) @@ -660,7 +670,19 @@ void host_disconnect(H3270 *h, int failed) if (CONNECTED || HALF_CONNECTED) { - x_remove_input(h); + // Disconecting, disable input + if(h->reading) + { + RemoveInput(h->ns_read_id); + h->reading = False; + } + if(h->excepting) + { + RemoveInput(h->ns_exception_id); + h->excepting = False; + } +// x_remove_input(h); + net_disconnect(h); Trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,toggled(RECONNECT),h->auto_reconnect_inprogress); diff --git a/init.c b/init.c index 308833f..ea3d472 100644 --- a/init.c +++ b/init.c @@ -149,8 +149,12 @@ static void lib3270_session_init(H3270 *hSession, const char *model) hSession->cursor = set_cursor; hSession->message = message; hSession->update_ssl = update_ssl; + hSession->sock = -1; + +#ifdef _WIN32 + hSession->sockEvent = NULL; +#endif // _WIN32 - hSession->sock = -1; hSession->model_num = -1; hSession->cstate = NOT_CONNECTED; hSession->oia_status = -1; diff --git a/telnet.c b/telnet.c index e98fa2e..c862a52 100644 --- a/telnet.c +++ b/telnet.c @@ -38,8 +38,8 @@ */ #if defined(_WIN32) - #include - #include + #include + #include #endif #include @@ -485,7 +485,7 @@ static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr * * @param session Handle to the session descriptor. * - * @return The file descriptor of the connected socket. + * @return 0 if ok, non zero if failed */ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Boolean *resolving, Boolean *pending) { @@ -676,27 +676,27 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo } /* all done */ -/* #if defined(_WIN32) - if (session->sock_handle == NULL) { + + if(session->sockEvent == NULL) + { char ename[256]; - sprintf(ename, "wc3270-%d", getpid()); + snprintf(ename, 255, "%s-%d", PACKAGE_NAME, getpid()); - session->sock_handle = CreateEvent(NULL, TRUE, FALSE, ename); - if (session->sock_handle == NULL) + session->sockEvent = CreateEvent(NULL, TRUE, FALSE, ename); + if(session->sockEvent == NULL) { lib3270_popup_dialog( session, LIB3270_NOTIFY_CRITICAL, N_( "Network startup error" ), N_( "Cannot create socket handle" ), "%s", win32_strerror(GetLastError()) ); - _exit(1); } } - if (WSAEventSelect(session->sock, session->sock_handle, FD_READ | FD_CONNECT | FD_CLOSE) != 0) + if (WSAEventSelect(session->sock, session->sockEvent, FD_READ | FD_CONNECT | FD_CLOSE) != 0) { lib3270_popup_dialog( session, LIB3270_NOTIFY_CRITICAL, @@ -706,13 +706,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo _exit(1); } - return (int) session->sock_handle; -#else - return session->sock; -#endif -*/ +#endif // WIN32 - return session->sock; + return 0; } #undef close_fail @@ -1272,9 +1268,10 @@ telnet_fsm(unsigned char c) break; case DM: trace_dsn("\n"); - if (syncing) { + if (syncing) + { syncing = 0; - x_except_on(&h3270,h3270.sock); + x_except_on(&h3270); } telnet_state = TNS_DATA; break; @@ -1944,7 +1941,13 @@ void net_exception(H3270 *session) if (!syncing) { syncing = 1; - x_except_off(session); + + if(session->excepting) + { + RemoveInput(session->ns_exception_id); + session->excepting = False; + } +// x_except_off(session); } } @@ -3173,7 +3176,7 @@ static int non_blocking(H3270 *session, Boolean on) if (SOCK_IOCTL(session->sock, FIONBIO, (int *) &i) < 0) { - popup_a_sockerr(session, N_( "ioctl(%s)" ), "FIONBIO"); + popup_a_sockerr(session,N_( "ioctl(%s)" ), "FIONBIO"); return -1; } @@ -3183,7 +3186,7 @@ static int non_blocking(H3270 *session, Boolean on) if ((f = fcntl(session->sock, F_GETFL, 0)) == -1) { - popup_an_errno(NULL,errno, N_( "fcntl(%s)" ), "F_GETFL" ); + popup_an_errno(session,errno, N_( "fcntl(%s)" ), "F_GETFL" ); return -1; } @@ -3194,7 +3197,7 @@ static int non_blocking(H3270 *session, Boolean on) if (fcntl(session->sock, F_SETFL, f) < 0) { - popup_an_errno(NULL,errno, N_( "fcntl(%s)" ), "F_GETFL"); + popup_an_errno(session,errno, N_( "fcntl(%s)" ), "F_GETFL"); return -1; } diff --git a/xio.c b/xio.c index 781f430..bcab469 100644 --- a/xio.c +++ b/xio.c @@ -53,17 +53,25 @@ /* * Called to set up input on a new network connection. */ -void x_add_input(H3270 *h,int net_sock) +/* +void x_add_input(H3270 *h) { - h->ns_exception_id = AddExcept(net_sock, h, net_exception); +#ifdef _WIN32 + h->ns_exception_id = AddExcept(h->sockEvent, h, net_exception); + h->excepting = True; + h->ns_read_id = AddInput(h->sockEvent, h, net_input); + h->reading = True; +#else + h->ns_exception_id = AddExcept(h->sock, h, net_exception); h->excepting = True; - h->ns_read_id = AddInput(net_sock, h, net_input); + h->ns_read_id = AddInput(h->sock, h, net_input); h->reading = True; +#endif // WIN32 } - +*/ /* * Called when an exception is received to disable further exceptions. - */ + */ /* void x_except_off(H3270 *h) { CHECK_SESSION_HANDLE(h); @@ -74,13 +82,14 @@ void x_except_off(H3270 *h) h->excepting = False; } } +*/ /* * Called when exception processing is complete to re-enable exceptions. * This includes removing and restoring reading, so the exceptions are always * processed first. */ -void x_except_on(H3270 *h,int net_sock) +void x_except_on(H3270 *h) { if(h->excepting) return; @@ -88,16 +97,24 @@ void x_except_on(H3270 *h,int net_sock) if(h->reading) RemoveInput(h->ns_read_id); - h->ns_exception_id = AddExcept(net_sock, h, net_exception); +#ifdef WIN32 + h->ns_exception_id = AddExcept(h->sockEvent, h, net_exception); h->excepting = True; if(h->reading) - h->ns_read_id = AddInput(net_sock, h, net_input); + h->ns_read_id = AddInput(h->sockEvent, h, net_input); +#else + h->ns_exception_id = AddExcept(h->sock, h, net_exception); + h->excepting = True; + + if(h->reading) + h->ns_read_id = AddInput(h->sock, h, net_input); +#endif // WIN32 } /* * Called to disable input on a closing network connection. - */ + */ /* void x_remove_input(H3270 *h) { if(h->reading) @@ -111,3 +128,4 @@ void x_remove_input(H3270 *h) h->excepting = False; } } +*/ diff --git a/xioc.h b/xioc.h index b334a6b..b2a3ac8 100644 --- a/xioc.h +++ b/xioc.h @@ -35,8 +35,8 @@ * Global declarations for xio.c. */ -LIB3270_INTERNAL void x_add_input(H3270 *h,int net_sock); +LIB3270_INTERNAL void x_add_input(H3270 *h); LIB3270_INTERNAL void x_except_off(H3270 *h); -LIB3270_INTERNAL void x_except_on(H3270 *h,int net_sock); +LIB3270_INTERNAL void x_except_on(H3270 *h); LIB3270_INTERNAL void x_remove_input(H3270 *h); -- libgit2 0.21.2