Commit 6fccf19ecf4f78938c8af839fd048c8744eafa3f

Authored by perry.werneck@gmail.com
1 parent 6739b90c

Iniciando jni android, ajustes no processo de conexão

Showing 2 changed files with 49 additions and 119 deletions   Show diff stats
@@ -623,8 +623,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -623,8 +623,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
623 } 623 }
624 #endif 624 #endif
625 625
626 - /* set the socket to be non-delaying */  
627 - if (non_blocking(session,False) < 0) 626 + /* set the socket to be non-delaying during connect */
  627 + if(non_blocking(session,False) < 0)
628 close_fail; 628 close_fail;
629 629
630 #if !defined(_WIN32) 630 #if !defined(_WIN32)
@@ -646,23 +646,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -646,23 +646,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
646 if(!rc) 646 if(!rc)
647 { 647 {
648 trace_dsn("Connected.\n"); 648 trace_dsn("Connected.\n");
649 -  
650 -// if(non_blocking(session,False) < 0)  
651 -// close_fail;  
652 -  
653 net_connected(session); 649 net_connected(session);
654 -  
655 -/*  
656 - break;  
657 - case SE_EWOULDBLOCK: // Connection in progress  
658 - case SE_EINPROGRESS:  
659 - *pending = True;  
660 - trace_dsn("Connection pending.\n");  
661 -#if !defined(_WIN32)  
662 - output_id = AddOutput(session->sock, session, output_possible);  
663 -#endif  
664 - break;  
665 -*/  
666 } 650 }
667 else 651 else
668 { 652 {
@@ -813,7 +797,6 @@ static void net_connected(H3270 *session) @@ -813,7 +797,6 @@ static void net_connected(H3270 *session)
813 } 797 }
814 else 798 else
815 { 799 {
816 - // non_blocking(session,False);  
817 rc = SSL_connect(session->ssl_con); 800 rc = SSL_connect(session->ssl_con);
818 801
819 if(rc != 1) 802 if(rc != 1)
@@ -837,7 +820,6 @@ static void net_connected(H3270 *session) @@ -837,7 +820,6 @@ static void net_connected(H3270 *session)
837 return; 820 return;
838 821
839 } 822 }
840 - non_blocking(session,True);  
841 } 823 }
842 824
843 // session->secure_connection = True; 825 // session->secure_connection = True;
@@ -911,30 +893,6 @@ static void connection_complete(void) @@ -911,30 +893,6 @@ static void connection_complete(void)
911 } 893 }
912 894
913 /* 895 /*
914 -#if !defined(_WIN32)  
915 -//  
916 -// output_possible  
917 -// Output is possible on the socket. Used only when a connection is  
918 -// pending, to determine that the connection is complete.  
919 -//  
920 -static void output_possible(H3270 *session)  
921 -{  
922 - trace("%s: %s",__FUNCTION__,HALF_CONNECTED ? "Half connected" : "Connected");  
923 - if (HALF_CONNECTED)  
924 - {  
925 - connection_complete();  
926 - }  
927 -  
928 - if (output_id)  
929 - {  
930 - RemoveInput(output_id);  
931 - output_id = 0L;  
932 - }  
933 -}  
934 -#endif  
935 -*/  
936 -  
937 -/*  
938 * net_disconnect 896 * net_disconnect
939 * Shut down the socket. 897 * Shut down the socket.
940 */ 898 */
@@ -990,17 +948,17 @@ void net_input(H3270 *session) @@ -990,17 +948,17 @@ void net_input(H3270 *session)
990 register unsigned char *cp; 948 register unsigned char *cp;
991 int nr; 949 int nr;
992 950
993 - if(!session)  
994 - session = &h3270; 951 + CHECK_SESSION_HANDLE(session);
995 952
996 -#if defined(_WIN32) /*[*/  
997 - for (;;)  
998 -#endif /*]*/ 953 +// #if defined(_WIN32)
  954 +// for (;;)
  955 +// #endif
999 { 956 {
1000 if (session->sock < 0) 957 if (session->sock < 0)
1001 return; 958 return;
1002 959
1003 -#if defined(_WIN32) /*[*/ 960 +/*
  961 +#if defined(_WIN32)
1004 if (HALF_CONNECTED) { 962 if (HALF_CONNECTED) {
1005 963
1006 if (connect(session->sock, &haddr.sa, sizeof(haddr)) < 0) { 964 if (connect(session->sock, &haddr.sa, sizeof(haddr)) < 0) {
@@ -1009,7 +967,7 @@ void net_input(H3270 *session) @@ -1009,7 +967,7 @@ void net_input(H3270 *session)
1009 switch (err) { 967 switch (err) {
1010 case WSAEISCONN: 968 case WSAEISCONN:
1011 connection_complete(); 969 connection_complete();
1012 - /* and go get data...? */ 970 + // and go get data...?
1013 break; 971 break;
1014 case WSAEALREADY: 972 case WSAEALREADY:
1015 case WSAEWOULDBLOCK: 973 case WSAEWOULDBLOCK:
@@ -1025,31 +983,26 @@ void net_input(H3270 *session) @@ -1025,31 +983,26 @@ void net_input(H3270 *session)
1025 } 983 }
1026 } 984 }
1027 } 985 }
1028 -#endif /*]*/ 986 +#endif
  987 +*/
1029 988
1030 #if defined(X3270_ANSI) /*[*/ 989 #if defined(X3270_ANSI) /*[*/
1031 ansi_data = 0; 990 ansi_data = 0;
1032 #endif /*]*/ 991 #endif /*]*/
1033 992
1034 -// #if defined(_WIN32)  
1035 -// (void) ResetEvent(session->sock_handle);  
1036 -//#endif /*]*/  
1037 -  
1038 #if defined(HAVE_LIBSSL) 993 #if defined(HAVE_LIBSSL)
1039 if (session->ssl_con != NULL) 994 if (session->ssl_con != NULL)
1040 nr = SSL_read(session->ssl_con, (char *) netrbuf, BUFSZ); 995 nr = SSL_read(session->ssl_con, (char *) netrbuf, BUFSZ);
1041 else 996 else
1042 -#endif // HAVE_LIBSSL  
1043 -/*  
1044 -#if defined(LOCAL_PROCESS)  
1045 - if (local_process)  
1046 - nr = read(sock, (char *) netrbuf, BUFSZ);  
1047 - else  
1048 -#endif  
1049 -*/  
1050 nr = recv(session->sock, (char *) netrbuf, BUFSZ, 0); 997 nr = recv(session->sock, (char *) netrbuf, BUFSZ, 0);
1051 - if (nr < 0) {  
1052 - if (socket_errno() == SE_EWOULDBLOCK) { 998 +#else
  999 + nr = recv(session->sock, (char *) netrbuf, BUFSZ, 0);
  1000 +#endif // HAVE_LIBSSL
  1001 +
  1002 + if (nr < 0)
  1003 + {
  1004 + if (socket_errno() == SE_EWOULDBLOCK)
  1005 + {
1053 return; 1006 return;
1054 } 1007 }
1055 #if defined(HAVE_LIBSSL) /*[*/ 1008 #if defined(HAVE_LIBSSL) /*[*/
@@ -1082,28 +1035,22 @@ void net_input(H3270 *session) @@ -1082,28 +1035,22 @@ void net_input(H3270 *session)
1082 connection_complete(); 1035 connection_complete();
1083 return; 1036 return;
1084 } 1037 }
1085 -/*  
1086 -#if defined(LOCAL_PROCESS) /  
1087 - if (errno == EIO && local_process) {  
1088 - trace_dsn("RCVD local process disconnect\n");  
1089 - host_disconnect(session,False);  
1090 - return;  
1091 - }  
1092 -#endif  
1093 -*/ 1038 +
1094 trace_dsn("RCVD socket error %d\n", errno); 1039 trace_dsn("RCVD socket error %d\n", errno);
  1040 +
1095 if (HALF_CONNECTED) 1041 if (HALF_CONNECTED)
1096 { 1042 {
1097 - popup_a_sockerr(NULL, N_( "%s:%d" ),h3270.hostname, h3270.current_port); 1043 + popup_a_sockerr(session, N_( "%s:%d" ),h3270.hostname, h3270.current_port);
1098 } 1044 }
1099 else if (socket_errno() != SE_ECONNRESET) 1045 else if (socket_errno() != SE_ECONNRESET)
1100 { 1046 {
1101 - popup_a_sockerr(NULL, N_( "Socket read error" ) ); 1047 + popup_a_sockerr(session, N_( "Socket read error" ) );
1102 } 1048 }
1103 1049
1104 host_disconnect(session,True); 1050 host_disconnect(session,True);
1105 return; 1051 return;
1106 - } else if (nr == 0) { 1052 + } else if (nr == 0)
  1053 + {
1107 /* Host disconnected. */ 1054 /* Host disconnected. */
1108 trace_dsn("RCVD disconnect\n"); 1055 trace_dsn("RCVD disconnect\n");
1109 host_disconnect(session,False); 1056 host_disconnect(session,False);
@@ -1123,50 +1070,31 @@ void net_input(H3270 *session) @@ -1123,50 +1070,31 @@ void net_input(H3270 *session)
1123 net_connected(session); 1070 net_connected(session);
1124 } 1071 }
1125 1072
1126 -#if defined(X3270_TRACE) /*[*/  
1127 trace_netdata('<', netrbuf, nr); 1073 trace_netdata('<', netrbuf, nr);
1128 -#endif /*]*/  
1129 1074
1130 ns_brcvd += nr; 1075 ns_brcvd += nr;
1131 - for (cp = netrbuf; cp < (netrbuf + nr); cp++) {  
1132 -/*  
1133 -#if defined(LOCAL_PROCESS)  
1134 - if (local_process) {  
1135 - // More to do here, probably.  
1136 - if (IN_NEITHER) { // now can assume ANSI mode  
1137 - host_in3270(CONNECTED_ANSI);  
1138 - hisopts[TELOPT_ECHO] = 1;  
1139 - check_linemode(False);  
1140 - kybdlock_clr(KL_AWAITING_FIRST, "telnet_fsm");  
1141 - status_reset();  
1142 - ps_process();  
1143 - }  
1144 - ansi_process((unsigned int) *cp);  
1145 - } else {  
1146 -#endif  
1147 -*/  
1148 - if (telnet_fsm(*cp))  
1149 - {  
1150 - (void) ctlr_dbcs_postprocess();  
1151 - host_disconnect(&h3270,True);  
1152 - return;  
1153 - }  
1154 -/*  
1155 -#if defined(LOCAL_PROCESS) 1076 + for (cp = netrbuf; cp < (netrbuf + nr); cp++)
  1077 + {
  1078 + if (telnet_fsm(*cp))
  1079 + {
  1080 + (void) ctlr_dbcs_postprocess();
  1081 + host_disconnect(session,True);
  1082 + return;
1156 } 1083 }
1157 -#endif  
1158 -*/  
1159 } 1084 }
1160 1085
1161 -#if defined(X3270_ANSI) /*[*/  
1162 - if (IN_ANSI) { 1086 +#if defined(X3270_ANSI)
  1087 + if (IN_ANSI)
  1088 + {
1163 (void) ctlr_dbcs_postprocess(); 1089 (void) ctlr_dbcs_postprocess();
1164 } 1090 }
1165 - if (ansi_data) { 1091 +
  1092 + if (ansi_data)
  1093 + {
1166 trace_dsn("\n"); 1094 trace_dsn("\n");
1167 ansi_data = 0; 1095 ansi_data = 0;
1168 } 1096 }
1169 -#endif /*]*/ 1097 +#endif // X3270_ANSI
1170 1098
1171 } 1099 }
1172 1100
@@ -2043,9 +1971,7 @@ net_rawout(unsigned const char *buf, int len) @@ -2043,9 +1971,7 @@ net_rawout(unsigned const char *buf, int len)
2043 { 1971 {
2044 int nw; 1972 int nw;
2045 1973
2046 -#if defined(X3270_TRACE) /*[*/  
2047 trace_netdata('>', buf, len); 1974 trace_netdata('>', buf, len);
2048 -#endif /*]*/  
2049 1975
2050 while (len) { 1976 while (len) {
2051 #if defined(OMTU) /*[*/ 1977 #if defined(OMTU) /*[*/
@@ -2633,7 +2559,7 @@ check_linemode(Boolean init) @@ -2633,7 +2559,7 @@ check_linemode(Boolean init)
2633 } 2559 }
2634 2560
2635 2561
2636 -#if defined(X3270_TRACE) /*[*/ 2562 +#if defined(X3270_TRACE)
2637 2563
2638 /* 2564 /*
2639 * nnn 2565 * nnn
@@ -2681,11 +2607,9 @@ opt(unsigned char c) @@ -2681,11 +2607,9 @@ opt(unsigned char c)
2681 return nnn((int)c); 2607 return nnn((int)c);
2682 } 2608 }
2683 2609
2684 -  
2685 #define LINEDUMP_MAX 32 2610 #define LINEDUMP_MAX 32
2686 2611
2687 -void  
2688 -trace_netdata(char direction, unsigned const char *buf, int len) 2612 +void trace_netdata(char direction, unsigned const char *buf, int len)
2689 { 2613 {
2690 int offset; 2614 int offset;
2691 struct timeval ts; 2615 struct timeval ts;
@@ -2708,7 +2632,7 @@ trace_netdata(char direction, unsigned const char *buf, int len) @@ -2708,7 +2632,7 @@ trace_netdata(char direction, unsigned const char *buf, int len)
2708 } 2632 }
2709 trace_dsn("\n"); 2633 trace_dsn("\n");
2710 } 2634 }
2711 -#endif /*]*/ 2635 +#endif // X3270_TRACE
2712 2636
2713 2637
2714 /* 2638 /*
@@ -55,9 +55,15 @@ LIB3270_INTERNAL void net_send_werase(void); @@ -55,9 +55,15 @@ LIB3270_INTERNAL void net_send_werase(void);
55 LIB3270_INTERNAL Boolean net_snap_options(void); 55 LIB3270_INTERNAL Boolean net_snap_options(void);
56 LIB3270_INTERNAL void space3270out(int n); 56 LIB3270_INTERNAL void space3270out(int n);
57 LIB3270_INTERNAL const char *tn3270e_current_opts(void); 57 LIB3270_INTERNAL const char *tn3270e_current_opts(void);
58 -LIB3270_INTERNAL void trace_netdata(char direction, unsigned const char *buf, int len);  
59 LIB3270_INTERNAL char *net_proxy_type(void); 58 LIB3270_INTERNAL char *net_proxy_type(void);
60 LIB3270_INTERNAL char *net_proxy_host(void); 59 LIB3270_INTERNAL char *net_proxy_host(void);
61 LIB3270_INTERNAL char *net_proxy_port(void); 60 LIB3270_INTERNAL char *net_proxy_port(void);
62 61
  62 +#if defined(X3270_TRACE)
  63 + LIB3270_INTERNAL void trace_netdata(char direction, unsigned const char *buf, int len);
  64 +#else
  65 + #define trace_netdata(direction, buf, len) /* */
  66 +#endif // X3270_TRACE
  67 +
  68 +
63 LIB3270_INTERNAL int net_getsockname(const H3270 *h3270, void *buf, int *len); 69 LIB3270_INTERNAL int net_getsockname(const H3270 *h3270, void *buf, int *len);