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 | 547 | /* Attempt contact. */ |
| 548 | 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 | 552 | /* Redundantly signal a disconnect. */ |
| 553 | 553 | host_disconnected(hSession); |
| ... | ... | @@ -572,7 +572,17 @@ static int do_connect(H3270 *hSession, const char *n) |
| 572 | 572 | // login_macro(ps); |
| 573 | 573 | |
| 574 | 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 | 587 | /* Set state and tell the world. */ |
| 578 | 588 | if (pending) |
| ... | ... | @@ -660,7 +670,19 @@ void host_disconnect(H3270 *h, int failed) |
| 660 | 670 | |
| 661 | 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 | 686 | net_disconnect(h); |
| 665 | 687 | |
| 666 | 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 | 149 | hSession->cursor = set_cursor; |
| 150 | 150 | hSession->message = message; |
| 151 | 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 | 158 | hSession->model_num = -1; |
| 155 | 159 | hSession->cstate = NOT_CONNECTED; |
| 156 | 160 | hSession->oia_status = -1; | ... | ... |
telnet.c
| ... | ... | @@ -38,8 +38,8 @@ |
| 38 | 38 | */ |
| 39 | 39 | |
| 40 | 40 | #if defined(_WIN32) |
| 41 | - #include <winsock2.h> | |
| 42 | - #include <windows.h> | |
| 41 | + #include <winsock2.h> | |
| 42 | + #include <windows.h> | |
| 43 | 43 | #endif |
| 44 | 44 | |
| 45 | 45 | #include <lib3270/config.h> |
| ... | ... | @@ -485,7 +485,7 @@ static int connect_sock(H3270 *hSession, int sockfd, const struct sockaddr *addr |
| 485 | 485 | * |
| 486 | 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 | 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 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /* all done */ |
| 679 | -/* | |
| 680 | 679 | #if defined(_WIN32) |
| 681 | - if (session->sock_handle == NULL) { | |
| 680 | + | |
| 681 | + if(session->sockEvent == NULL) | |
| 682 | + { | |
| 682 | 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 | 690 | lib3270_popup_dialog( session, |
| 690 | 691 | LIB3270_NOTIFY_CRITICAL, |
| 691 | 692 | N_( "Network startup error" ), |
| 692 | 693 | N_( "Cannot create socket handle" ), |
| 693 | 694 | "%s", win32_strerror(GetLastError()) ); |
| 694 | - | |
| 695 | 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 | 701 | lib3270_popup_dialog( session, |
| 702 | 702 | LIB3270_NOTIFY_CRITICAL, |
| ... | ... | @@ -706,13 +706,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo |
| 706 | 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 | 713 | #undef close_fail |
| 718 | 714 | |
| ... | ... | @@ -1272,9 +1268,10 @@ telnet_fsm(unsigned char c) |
| 1272 | 1268 | break; |
| 1273 | 1269 | case DM: |
| 1274 | 1270 | trace_dsn("\n"); |
| 1275 | - if (syncing) { | |
| 1271 | + if (syncing) | |
| 1272 | + { | |
| 1276 | 1273 | syncing = 0; |
| 1277 | - x_except_on(&h3270,h3270.sock); | |
| 1274 | + x_except_on(&h3270); | |
| 1278 | 1275 | } |
| 1279 | 1276 | telnet_state = TNS_DATA; |
| 1280 | 1277 | break; |
| ... | ... | @@ -1944,7 +1941,13 @@ void net_exception(H3270 *session) |
| 1944 | 1941 | if (!syncing) |
| 1945 | 1942 | { |
| 1946 | 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 | 3176 | |
| 3174 | 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 | 3180 | return -1; |
| 3178 | 3181 | } |
| 3179 | 3182 | |
| ... | ... | @@ -3183,7 +3186,7 @@ static int non_blocking(H3270 *session, Boolean on) |
| 3183 | 3186 | |
| 3184 | 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 | 3190 | return -1; |
| 3188 | 3191 | } |
| 3189 | 3192 | |
| ... | ... | @@ -3194,7 +3197,7 @@ static int non_blocking(H3270 *session, Boolean on) |
| 3194 | 3197 | |
| 3195 | 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 | 3201 | return -1; |
| 3199 | 3202 | } |
| 3200 | 3203 | ... | ... |
| ... | ... | @@ -53,17 +53,25 @@ |
| 53 | 53 | /* |
| 54 | 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 | 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 | 68 | h->reading = True; |
| 69 | +#endif // WIN32 | |
| 62 | 70 | } |
| 63 | - | |
| 71 | +*/ | |
| 64 | 72 | /* |
| 65 | 73 | * Called when an exception is received to disable further exceptions. |
| 66 | - */ | |
| 74 | + */ /* | |
| 67 | 75 | void x_except_off(H3270 *h) |
| 68 | 76 | { |
| 69 | 77 | CHECK_SESSION_HANDLE(h); |
| ... | ... | @@ -74,13 +82,14 @@ void x_except_off(H3270 *h) |
| 74 | 82 | h->excepting = False; |
| 75 | 83 | } |
| 76 | 84 | } |
| 85 | +*/ | |
| 77 | 86 | |
| 78 | 87 | /* |
| 79 | 88 | * Called when exception processing is complete to re-enable exceptions. |
| 80 | 89 | * This includes removing and restoring reading, so the exceptions are always |
| 81 | 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 | 94 | if(h->excepting) |
| 86 | 95 | return; |
| ... | ... | @@ -88,16 +97,24 @@ void x_except_on(H3270 *h,int net_sock) |
| 88 | 97 | if(h->reading) |
| 89 | 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 | 102 | h->excepting = True; |
| 93 | 103 | |
| 94 | 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 | 116 | * Called to disable input on a closing network connection. |
| 100 | - */ | |
| 117 | + */ /* | |
| 101 | 118 | void x_remove_input(H3270 *h) |
| 102 | 119 | { |
| 103 | 120 | if(h->reading) |
| ... | ... | @@ -111,3 +128,4 @@ void x_remove_input(H3270 *h) |
| 111 | 128 | h->excepting = False; |
| 112 | 129 | } |
| 113 | 130 | } |
| 131 | +*/ | ... | ... |
xioc.h
| ... | ... | @@ -35,8 +35,8 @@ |
| 35 | 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 | 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 | 41 | LIB3270_INTERNAL void x_remove_input(H3270 *h); |
| 42 | 42 | ... | ... |