Commit 62771f9d2865a0bb44cb0b59dd95259aeac7fd38

Authored by perry.werneck@gmail.com
1 parent bbbc9421

Android: Iniciando implementação de conexão ao host usando socket do próprio android

Showing 2 changed files with 49 additions and 38 deletions   Show diff stats
@@ -118,7 +118,7 @@ LIB3270_INTERNAL enum dbcs_state ctlr_dbcs_state(int baddr); @@ -118,7 +118,7 @@ LIB3270_INTERNAL enum dbcs_state ctlr_dbcs_state(int baddr);
118 LIB3270_INTERNAL enum dbcs_state ctlr_lookleft_state(int baddr, enum dbcs_why *why); 118 LIB3270_INTERNAL enum dbcs_state ctlr_lookleft_state(int baddr, enum dbcs_why *why);
119 LIB3270_INTERNAL int ctlr_dbcs_postprocess(void); 119 LIB3270_INTERNAL int ctlr_dbcs_postprocess(void);
120 #else /*][*/ 120 #else /*][*/
121 -#define ctlr_dbcs_state(b) DBCS_NONE  
122 -#define ctlr_lookleft_state(b, w) DBCS_NONE  
123 -#define ctlr_dbcs_postprocess() 0 121 + #define ctlr_dbcs_state(b) DBCS_NONE
  122 + #define ctlr_lookleft_state(b, w) DBCS_NONE
  123 + #define ctlr_dbcs_postprocess() 0
124 #endif /*]*/ 124 #endif /*]*/
@@ -965,6 +965,38 @@ void net_disconnect(H3270 *session) @@ -965,6 +965,38 @@ void net_disconnect(H3270 *session)
965 965
966 } 966 }
967 967
  968 +
  969 +LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned char *netrbuf)
  970 +{
  971 + register const unsigned char * cp;
  972 +
  973 + trace_netdata('<', netrbuf, nr);
  974 +
  975 + hSession->ns_brcvd += nr;
  976 + for (cp = netrbuf; cp < (netrbuf + nr); cp++)
  977 + {
  978 + if(telnet_fsm(hSession,*cp))
  979 + {
  980 + (void) ctlr_dbcs_postprocess();
  981 + host_disconnect(hSession,True);
  982 + return;
  983 + }
  984 + }
  985 +
  986 +#if defined(X3270_ANSI)
  987 + if (IN_ANSI)
  988 + {
  989 + (void) ctlr_dbcs_postprocess();
  990 + }
  991 +
  992 + if (hSession->ansi_data)
  993 + {
  994 + trace_dsn("\n");
  995 + hSession->ansi_data = 0;
  996 + }
  997 +#endif // X3270_ANSI
  998 +}
  999 +
968 1000
969 /* 1001 /*
970 * net_input 1002 * net_input
@@ -974,8 +1006,9 @@ void net_disconnect(H3270 *session) @@ -974,8 +1006,9 @@ void net_disconnect(H3270 *session)
974 */ 1006 */
975 void net_input(H3270 *session) 1007 void net_input(H3270 *session)
976 { 1008 {
977 - register unsigned char *cp;  
978 - int nr; 1009 +// register unsigned char * cp;
  1010 + int nr;
  1011 + unsigned char buffer[BUFSZ];
979 1012
980 CHECK_SESSION_HANDLE(session); 1013 CHECK_SESSION_HANDLE(session);
981 1014
@@ -986,46 +1019,21 @@ void net_input(H3270 *session) @@ -986,46 +1019,21 @@ void net_input(H3270 *session)
986 if (session->sock < 0) 1019 if (session->sock < 0)
987 return; 1020 return;
988 1021
989 -/*  
990 -#if defined(_WIN32)  
991 - if (HALF_CONNECTED) {  
992 -  
993 - if (connect(session->sock, &haddr.sa, sizeof(haddr)) < 0) {  
994 - int err = GetLastError();  
995 -  
996 - switch (err) {  
997 - case WSAEISCONN:  
998 - connection_complete(session);  
999 - // and go get data...?  
1000 - break;  
1001 - case WSAEALREADY:  
1002 - case WSAEWOULDBLOCK:  
1003 - case WSAEINVAL:  
1004 - return;  
1005 - default:  
1006 - lib3270_popup_dialog(session,LIB3270_NOTIFY_CRITICAL,N_( "Network startup error" ),N_( "Second connect() failed" ),"%s", win32_strerror(GetLastError()) );  
1007 - _exit(1);  
1008 - }  
1009 - }  
1010 - } 1022 +#if defined(X3270_ANSI)
  1023 + session->ansi_data = 0;
1011 #endif 1024 #endif
1012 -*/  
1013 -  
1014 -#if defined(X3270_ANSI) /*[*/  
1015 - session->ansi_data = 0;  
1016 -#endif /*]*/  
1017 1025
1018 #if defined(_WIN32) 1026 #if defined(_WIN32)
1019 - ResetEvent(session->sockEvent); 1027 + ResetEvent(session->sockEvent);
1020 #endif 1028 #endif
1021 1029
1022 #if defined(HAVE_LIBSSL) 1030 #if defined(HAVE_LIBSSL)
1023 if (session->ssl_con != NULL) 1031 if (session->ssl_con != NULL)
1024 - nr = SSL_read(session->ssl_con, (char *) session->netrbuf, BUFSZ); 1032 + nr = SSL_read(session->ssl_con, (char *) buffer, BUFSZ);
1025 else 1033 else
1026 - nr = recv(session->sock, (char *) session->netrbuf, BUFSZ, 0); 1034 + nr = recv(session->sock, (char *) buffer, BUFSZ, 0);
1027 #else 1035 #else
1028 - nr = recv(session->sock, (char *) session->netrbuf, BUFSZ, 0); 1036 + nr = recv(session->sock, (char *) buffer, BUFSZ, 0);
1029 #endif // HAVE_LIBSSL 1037 #endif // HAVE_LIBSSL
1030 1038
1031 if (nr < 0) 1039 if (nr < 0)
@@ -1064,7 +1072,7 @@ void net_input(H3270 *session) @@ -1064,7 +1072,7 @@ void net_input(H3270 *session)
1064 1072
1065 if (HALF_CONNECTED) 1073 if (HALF_CONNECTED)
1066 { 1074 {
1067 - popup_a_sockerr(session, N_( "%s:%d" ),h3270.hostname, h3270.current_port); 1075 + popup_a_sockerr(session, N_( "%s:%d" ),session->hostname, session->current_port);
1068 } 1076 }
1069 else if (socket_errno() != SE_ECONNRESET) 1077 else if (socket_errno() != SE_ECONNRESET)
1070 { 1078 {
@@ -1093,6 +1101,9 @@ void net_input(H3270 *session) @@ -1093,6 +1101,9 @@ void net_input(H3270 *session)
1093 net_connected(session); 1101 net_connected(session);
1094 } 1102 }
1095 1103
  1104 + lib3270_data_recv(session, nr, buffer);
  1105 +
  1106 +/*
1096 trace_netdata('<', session->netrbuf, nr); 1107 trace_netdata('<', session->netrbuf, nr);
1097 1108
1098 session->ns_brcvd += nr; 1109 session->ns_brcvd += nr;
@@ -1118,7 +1129,7 @@ void net_input(H3270 *session) @@ -1118,7 +1129,7 @@ void net_input(H3270 *session)
1118 session->ansi_data = 0; 1129 session->ansi_data = 0;
1119 } 1130 }
1120 #endif // X3270_ANSI 1131 #endif // X3270_ANSI
1121 - 1132 +*/
1122 } 1133 }
1123 1134
1124 } 1135 }