Commit b20e58395785cc1cc872b8926c601816dc3cdfc5
1 parent
886d59dd
Exists in
master
and in
3 other branches
Simplificando código, reincluindo semaforo windows
Showing
5 changed files
with
84 additions
and
37 deletions
Show diff stats
host.c
@@ -547,7 +547,7 @@ static int do_connect(H3270 *hSession, const char *n) | @@ -547,7 +547,7 @@ static int do_connect(H3270 *hSession, const char *n) | ||
547 | /* Attempt contact. */ | 547 | /* Attempt contact. */ |
548 | hSession->ever_3270 = False; | 548 | hSession->ever_3270 = False; |
549 | 549 | ||
550 | - if(net_connect(hSession, chost, port, 0, &resolving,&pending) < 0 && !resolving) | 550 | + if(net_connect(hSession, chost, port, 0, &resolving,&pending) != 0 && !resolving) |
551 | { | 551 | { |
552 | /* Redundantly signal a disconnect. */ | 552 | /* Redundantly signal a disconnect. */ |
553 | host_disconnected(hSession); | 553 | host_disconnected(hSession); |
@@ -572,7 +572,17 @@ static int do_connect(H3270 *hSession, const char *n) | @@ -572,7 +572,17 @@ static int do_connect(H3270 *hSession, const char *n) | ||
572 | // login_macro(ps); | 572 | // login_macro(ps); |
573 | 573 | ||
574 | /* Prepare Xt for I/O. */ | 574 | /* Prepare Xt for I/O. */ |
575 | - x_add_input(hSession,hSession->sock); | 575 | +// x_add_input(hSession); |
576 | +#ifdef _WIN32 | ||
577 | + hSession->ns_exception_id = AddExcept(hSession->sockEvent, hSession, net_exception); | ||
578 | + hSession->ns_read_id = AddInput(hSession->sockEvent, hSession, net_input); | ||
579 | +#else | ||
580 | + hSession->ns_exception_id = AddExcept(hSession->sock, hSession, net_exception); | ||
581 | + hSession->ns_read_id = AddInput(hSession->sock, hSession, net_input); | ||
582 | +#endif // WIN32 | ||
583 | + | ||
584 | + hSession->excepting = True; | ||
585 | + hSession->reading = True; | ||
576 | 586 | ||
577 | /* Set state and tell the world. */ | 587 | /* Set state and tell the world. */ |
578 | if (pending) | 588 | if (pending) |
@@ -660,7 +670,19 @@ void host_disconnect(H3270 *h, int failed) | @@ -660,7 +670,19 @@ void host_disconnect(H3270 *h, int failed) | ||
660 | 670 | ||
661 | if (CONNECTED || HALF_CONNECTED) | 671 | if (CONNECTED || HALF_CONNECTED) |
662 | { | 672 | { |
663 | - x_remove_input(h); | 673 | + // Disconecting, disable input |
674 | + if(h->reading) | ||
675 | + { | ||
676 | + RemoveInput(h->ns_read_id); | ||
677 | + h->reading = False; | ||
678 | + } | ||
679 | + if(h->excepting) | ||
680 | + { | ||
681 | + RemoveInput(h->ns_exception_id); | ||
682 | + h->excepting = False; | ||
683 | + } | ||
684 | +// x_remove_input(h); | ||
685 | + | ||
664 | net_disconnect(h); | 686 | net_disconnect(h); |
665 | 687 | ||
666 | Trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,toggled(RECONNECT),h->auto_reconnect_inprogress); | 688 | Trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,toggled(RECONNECT),h->auto_reconnect_inprogress); |
init.c
@@ -149,8 +149,12 @@ static void lib3270_session_init(H3270 *hSession, const char *model) | @@ -149,8 +149,12 @@ static void lib3270_session_init(H3270 *hSession, const char *model) | ||
149 | hSession->cursor = set_cursor; | 149 | hSession->cursor = set_cursor; |
150 | hSession->message = message; | 150 | hSession->message = message; |
151 | hSession->update_ssl = update_ssl; | 151 | hSession->update_ssl = update_ssl; |
152 | + hSession->sock = -1; | ||
153 | + | ||
154 | +#ifdef _WIN32 | ||
155 | + hSession->sockEvent = NULL; | ||
156 | +#endif // _WIN32 | ||
152 | 157 | ||
153 | - hSession->sock = -1; | ||
154 | hSession->model_num = -1; | 158 | hSession->model_num = -1; |
155 | hSession->cstate = NOT_CONNECTED; | 159 | hSession->cstate = NOT_CONNECTED; |
156 | hSession->oia_status = -1; | 160 | hSession->oia_status = -1; |
telnet.c
@@ -38,8 +38,8 @@ | @@ -38,8 +38,8 @@ | ||
38 | */ | 38 | */ |
39 | 39 | ||
40 | #if defined(_WIN32) | 40 | #if defined(_WIN32) |
41 | - #include <winsock2.h> | ||
42 | - #include <windows.h> | 41 | + #include <winsock2.h> |
42 | + #include <windows.h> | ||
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #include <lib3270/config.h> | 45 | #include <lib3270/config.h> |
@@ -485,7 +485,7 @@ static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr | @@ -485,7 +485,7 @@ static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr | ||
485 | * | 485 | * |
486 | * @param session Handle to the session descriptor. | 486 | * @param session Handle to the session descriptor. |
487 | * | 487 | * |
488 | - * @return The file descriptor of the connected socket. | 488 | + * @return 0 if ok, non zero if failed |
489 | */ | 489 | */ |
490 | int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Boolean *resolving, Boolean *pending) | 490 | int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Boolean *resolving, Boolean *pending) |
491 | { | 491 | { |
@@ -676,27 +676,27 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | @@ -676,27 +676,27 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | ||
676 | } | 676 | } |
677 | 677 | ||
678 | /* all done */ | 678 | /* all done */ |
679 | -/* | ||
680 | #if defined(_WIN32) | 679 | #if defined(_WIN32) |
681 | - if (session->sock_handle == NULL) { | 680 | + |
681 | + if(session->sockEvent == NULL) | ||
682 | + { | ||
682 | char ename[256]; | 683 | char ename[256]; |
683 | 684 | ||
684 | - sprintf(ename, "wc3270-%d", getpid()); | 685 | + snprintf(ename, 255, "%s-%d", PACKAGE_NAME, getpid()); |
685 | 686 | ||
686 | - session->sock_handle = CreateEvent(NULL, TRUE, FALSE, ename); | ||
687 | - if (session->sock_handle == NULL) | 687 | + session->sockEvent = CreateEvent(NULL, TRUE, FALSE, ename); |
688 | + if(session->sockEvent == NULL) | ||
688 | { | 689 | { |
689 | lib3270_popup_dialog( session, | 690 | lib3270_popup_dialog( session, |
690 | LIB3270_NOTIFY_CRITICAL, | 691 | LIB3270_NOTIFY_CRITICAL, |
691 | N_( "Network startup error" ), | 692 | N_( "Network startup error" ), |
692 | N_( "Cannot create socket handle" ), | 693 | N_( "Cannot create socket handle" ), |
693 | "%s", win32_strerror(GetLastError()) ); | 694 | "%s", win32_strerror(GetLastError()) ); |
694 | - | ||
695 | _exit(1); | 695 | _exit(1); |
696 | } | 696 | } |
697 | } | 697 | } |
698 | 698 | ||
699 | - if (WSAEventSelect(session->sock, session->sock_handle, FD_READ | FD_CONNECT | FD_CLOSE) != 0) | 699 | + if (WSAEventSelect(session->sock, session->sockEvent, FD_READ | FD_CONNECT | FD_CLOSE) != 0) |
700 | { | 700 | { |
701 | lib3270_popup_dialog( session, | 701 | lib3270_popup_dialog( session, |
702 | LIB3270_NOTIFY_CRITICAL, | 702 | LIB3270_NOTIFY_CRITICAL, |
@@ -706,13 +706,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | @@ -706,13 +706,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | ||
706 | _exit(1); | 706 | _exit(1); |
707 | } | 707 | } |
708 | 708 | ||
709 | - return (int) session->sock_handle; | ||
710 | -#else | ||
711 | - return session->sock; | ||
712 | -#endif | ||
713 | -*/ | 709 | +#endif // WIN32 |
714 | 710 | ||
715 | - return session->sock; | 711 | + return 0; |
716 | } | 712 | } |
717 | #undef close_fail | 713 | #undef close_fail |
718 | 714 | ||
@@ -1272,9 +1268,10 @@ telnet_fsm(unsigned char c) | @@ -1272,9 +1268,10 @@ telnet_fsm(unsigned char c) | ||
1272 | break; | 1268 | break; |
1273 | case DM: | 1269 | case DM: |
1274 | trace_dsn("\n"); | 1270 | trace_dsn("\n"); |
1275 | - if (syncing) { | 1271 | + if (syncing) |
1272 | + { | ||
1276 | syncing = 0; | 1273 | syncing = 0; |
1277 | - x_except_on(&h3270,h3270.sock); | 1274 | + x_except_on(&h3270); |
1278 | } | 1275 | } |
1279 | telnet_state = TNS_DATA; | 1276 | telnet_state = TNS_DATA; |
1280 | break; | 1277 | break; |
@@ -1944,7 +1941,13 @@ void net_exception(H3270 *session) | @@ -1944,7 +1941,13 @@ void net_exception(H3270 *session) | ||
1944 | if (!syncing) | 1941 | if (!syncing) |
1945 | { | 1942 | { |
1946 | syncing = 1; | 1943 | syncing = 1; |
1947 | - x_except_off(session); | 1944 | + |
1945 | + if(session->excepting) | ||
1946 | + { | ||
1947 | + RemoveInput(session->ns_exception_id); | ||
1948 | + session->excepting = False; | ||
1949 | + } | ||
1950 | +// x_except_off(session); | ||
1948 | } | 1951 | } |
1949 | } | 1952 | } |
1950 | 1953 | ||
@@ -3173,7 +3176,7 @@ static int non_blocking(H3270 *session, Boolean on) | @@ -3173,7 +3176,7 @@ static int non_blocking(H3270 *session, Boolean on) | ||
3173 | 3176 | ||
3174 | if (SOCK_IOCTL(session->sock, FIONBIO, (int *) &i) < 0) | 3177 | if (SOCK_IOCTL(session->sock, FIONBIO, (int *) &i) < 0) |
3175 | { | 3178 | { |
3176 | - popup_a_sockerr(session, N_( "ioctl(%s)" ), "FIONBIO"); | 3179 | + popup_a_sockerr(session,N_( "ioctl(%s)" ), "FIONBIO"); |
3177 | return -1; | 3180 | return -1; |
3178 | } | 3181 | } |
3179 | 3182 | ||
@@ -3183,7 +3186,7 @@ static int non_blocking(H3270 *session, Boolean on) | @@ -3183,7 +3186,7 @@ static int non_blocking(H3270 *session, Boolean on) | ||
3183 | 3186 | ||
3184 | if ((f = fcntl(session->sock, F_GETFL, 0)) == -1) | 3187 | if ((f = fcntl(session->sock, F_GETFL, 0)) == -1) |
3185 | { | 3188 | { |
3186 | - popup_an_errno(NULL,errno, N_( "fcntl(%s)" ), "F_GETFL" ); | 3189 | + popup_an_errno(session,errno, N_( "fcntl(%s)" ), "F_GETFL" ); |
3187 | return -1; | 3190 | return -1; |
3188 | } | 3191 | } |
3189 | 3192 | ||
@@ -3194,7 +3197,7 @@ static int non_blocking(H3270 *session, Boolean on) | @@ -3194,7 +3197,7 @@ static int non_blocking(H3270 *session, Boolean on) | ||
3194 | 3197 | ||
3195 | if (fcntl(session->sock, F_SETFL, f) < 0) | 3198 | if (fcntl(session->sock, F_SETFL, f) < 0) |
3196 | { | 3199 | { |
3197 | - popup_an_errno(NULL,errno, N_( "fcntl(%s)" ), "F_GETFL"); | 3200 | + popup_an_errno(session,errno, N_( "fcntl(%s)" ), "F_GETFL"); |
3198 | return -1; | 3201 | return -1; |
3199 | } | 3202 | } |
3200 | 3203 |
@@ -53,17 +53,25 @@ | @@ -53,17 +53,25 @@ | ||
53 | /* | 53 | /* |
54 | * Called to set up input on a new network connection. | 54 | * Called to set up input on a new network connection. |
55 | */ | 55 | */ |
56 | -void x_add_input(H3270 *h,int net_sock) | 56 | +/* |
57 | +void x_add_input(H3270 *h) | ||
57 | { | 58 | { |
58 | - h->ns_exception_id = AddExcept(net_sock, h, net_exception); | 59 | +#ifdef _WIN32 |
60 | + h->ns_exception_id = AddExcept(h->sockEvent, h, net_exception); | ||
61 | + h->excepting = True; | ||
62 | + h->ns_read_id = AddInput(h->sockEvent, h, net_input); | ||
63 | + h->reading = True; | ||
64 | +#else | ||
65 | + h->ns_exception_id = AddExcept(h->sock, h, net_exception); | ||
59 | h->excepting = True; | 66 | h->excepting = True; |
60 | - h->ns_read_id = AddInput(net_sock, h, net_input); | 67 | + h->ns_read_id = AddInput(h->sock, h, net_input); |
61 | h->reading = True; | 68 | h->reading = True; |
69 | +#endif // WIN32 | ||
62 | } | 70 | } |
63 | - | 71 | +*/ |
64 | /* | 72 | /* |
65 | * Called when an exception is received to disable further exceptions. | 73 | * Called when an exception is received to disable further exceptions. |
66 | - */ | 74 | + */ /* |
67 | void x_except_off(H3270 *h) | 75 | void x_except_off(H3270 *h) |
68 | { | 76 | { |
69 | CHECK_SESSION_HANDLE(h); | 77 | CHECK_SESSION_HANDLE(h); |
@@ -74,13 +82,14 @@ void x_except_off(H3270 *h) | @@ -74,13 +82,14 @@ void x_except_off(H3270 *h) | ||
74 | h->excepting = False; | 82 | h->excepting = False; |
75 | } | 83 | } |
76 | } | 84 | } |
85 | +*/ | ||
77 | 86 | ||
78 | /* | 87 | /* |
79 | * Called when exception processing is complete to re-enable exceptions. | 88 | * Called when exception processing is complete to re-enable exceptions. |
80 | * This includes removing and restoring reading, so the exceptions are always | 89 | * This includes removing and restoring reading, so the exceptions are always |
81 | * processed first. | 90 | * processed first. |
82 | */ | 91 | */ |
83 | -void x_except_on(H3270 *h,int net_sock) | 92 | +void x_except_on(H3270 *h) |
84 | { | 93 | { |
85 | if(h->excepting) | 94 | if(h->excepting) |
86 | return; | 95 | return; |
@@ -88,16 +97,24 @@ void x_except_on(H3270 *h,int net_sock) | @@ -88,16 +97,24 @@ void x_except_on(H3270 *h,int net_sock) | ||
88 | if(h->reading) | 97 | if(h->reading) |
89 | RemoveInput(h->ns_read_id); | 98 | RemoveInput(h->ns_read_id); |
90 | 99 | ||
91 | - h->ns_exception_id = AddExcept(net_sock, h, net_exception); | 100 | +#ifdef WIN32 |
101 | + h->ns_exception_id = AddExcept(h->sockEvent, h, net_exception); | ||
92 | h->excepting = True; | 102 | h->excepting = True; |
93 | 103 | ||
94 | if(h->reading) | 104 | if(h->reading) |
95 | - h->ns_read_id = AddInput(net_sock, h, net_input); | 105 | + h->ns_read_id = AddInput(h->sockEvent, h, net_input); |
106 | +#else | ||
107 | + h->ns_exception_id = AddExcept(h->sock, h, net_exception); | ||
108 | + h->excepting = True; | ||
109 | + | ||
110 | + if(h->reading) | ||
111 | + h->ns_read_id = AddInput(h->sock, h, net_input); | ||
112 | +#endif // WIN32 | ||
96 | } | 113 | } |
97 | 114 | ||
98 | /* | 115 | /* |
99 | * Called to disable input on a closing network connection. | 116 | * Called to disable input on a closing network connection. |
100 | - */ | 117 | + */ /* |
101 | void x_remove_input(H3270 *h) | 118 | void x_remove_input(H3270 *h) |
102 | { | 119 | { |
103 | if(h->reading) | 120 | if(h->reading) |
@@ -111,3 +128,4 @@ void x_remove_input(H3270 *h) | @@ -111,3 +128,4 @@ void x_remove_input(H3270 *h) | ||
111 | h->excepting = False; | 128 | h->excepting = False; |
112 | } | 129 | } |
113 | } | 130 | } |
131 | +*/ |
xioc.h
@@ -35,8 +35,8 @@ | @@ -35,8 +35,8 @@ | ||
35 | * Global declarations for xio.c. | 35 | * Global declarations for xio.c. |
36 | */ | 36 | */ |
37 | 37 | ||
38 | -LIB3270_INTERNAL void x_add_input(H3270 *h,int net_sock); | 38 | +LIB3270_INTERNAL void x_add_input(H3270 *h); |
39 | LIB3270_INTERNAL void x_except_off(H3270 *h); | 39 | LIB3270_INTERNAL void x_except_off(H3270 *h); |
40 | -LIB3270_INTERNAL void x_except_on(H3270 *h,int net_sock); | 40 | +LIB3270_INTERNAL void x_except_on(H3270 *h); |
41 | LIB3270_INTERNAL void x_remove_input(H3270 *h); | 41 | LIB3270_INTERNAL void x_remove_input(H3270 *h); |
42 | 42 |