Commit b0e8702af8a8dc6fe2dbd863d458fd80c0cf05bb
1 parent
9ed6bd9a
Exists in
master
and in
5 other branches
Android - Melhorando processo de desconexão/conexão
Showing
1 changed file
with
39 additions
and
41 deletions
Show diff stats
android/src/br/com/bb/pw3270/lib3270.java
@@ -194,7 +194,16 @@ public abstract class lib3270 | @@ -194,7 +194,16 @@ public abstract class lib3270 | ||
194 | public void onFinish() | 194 | public void onFinish() |
195 | { | 195 | { |
196 | Log.d(TAG, "Timer " + id + " finished"); | 196 | Log.d(TAG, "Timer " + id + " finished"); |
197 | - terminal.timerFinish(id); | 197 | + |
198 | + Thread t = new Thread() | ||
199 | + { | ||
200 | + public void run() | ||
201 | + { | ||
202 | + terminal.timerFinish(id); | ||
203 | + } | ||
204 | + }; | ||
205 | + | ||
206 | + t.start(); | ||
198 | } | 207 | } |
199 | 208 | ||
200 | } | 209 | } |
@@ -215,7 +224,7 @@ public abstract class lib3270 | @@ -215,7 +224,7 @@ public abstract class lib3270 | ||
215 | 224 | ||
216 | protected int send_data(byte[] data, int len) | 225 | protected int send_data(byte[] data, int len) |
217 | { | 226 | { |
218 | - Log.i(TAG, "Bytes a enviar: " + len); | 227 | + Log.d(TAG, "Bytes a enviar: " + len); |
219 | 228 | ||
220 | try | 229 | try |
221 | { | 230 | { |
@@ -233,12 +242,11 @@ public abstract class lib3270 | @@ -233,12 +242,11 @@ public abstract class lib3270 | ||
233 | if (msg == null) | 242 | if (msg == null) |
234 | msg = ""; | 243 | msg = ""; |
235 | 244 | ||
236 | - Log.i(TAG, "Erro ao enviar dados: " + msg); | 245 | + Log.d(TAG, "Erro ao enviar dados: " + msg); |
237 | 246 | ||
238 | postPopup(1, "Desconectado", "Erro de comunicação ao enviar dados", msg); | 247 | postPopup(1, "Desconectado", "Erro de comunicação ao enviar dados", msg); |
239 | 248 | ||
240 | - connected = false; | ||
241 | - | 249 | + net_cleanup(); |
242 | } | 250 | } |
243 | return -1; | 251 | return -1; |
244 | } | 252 | } |
@@ -312,29 +320,31 @@ public abstract class lib3270 | @@ -312,29 +320,31 @@ public abstract class lib3270 | ||
312 | { | 320 | { |
313 | set_connection_status(true); | 321 | set_connection_status(true); |
314 | 322 | ||
315 | - while (connected) | 323 | + try |
324 | + { | ||
325 | + sock.setSoTimeout(100); | ||
326 | + } catch (Exception e) { connected = false; } | ||
327 | + | ||
328 | + while (connected && sock.isConnected() ) | ||
316 | { | 329 | { |
317 | - byte[] in = new byte[16384]; | ||
318 | - int sz = -1; | ||
319 | - | ||
320 | try | 330 | try |
321 | { | 331 | { |
322 | - sz = inData.read(in, 0, 16384); | 332 | + byte[] in = new byte[16384]; |
323 | 333 | ||
324 | - } catch (Exception e) | ||
325 | - { | ||
326 | - String msg = e.getLocalizedMessage(); | ||
327 | - Log.i(TAG, "Erro ao receber dados do host: " + msg); | ||
328 | - postPopup(1, "Desconectado", "Erro de comunicação ao receber dados", msg); | ||
329 | - connected = false; | ||
330 | - sz = -1; | ||
331 | - } | 334 | + int sz = inData.read(in, 0, 16384); |
332 | 335 | ||
333 | - if (sz > 0) | ||
334 | - procRecvdata(in,sz); | 336 | + if (sz > 0) |
337 | + procRecvdata(in,sz); | ||
335 | 338 | ||
336 | - } | 339 | + } catch (Exception e) { } |
337 | 340 | ||
341 | + } | ||
342 | + | ||
343 | + if(connected) | ||
344 | + { | ||
345 | + postPopup(1, "Desconectado", "Erro de comunicação ao receber dados", ""); | ||
346 | + connected = false; | ||
347 | + } | ||
338 | } | 348 | } |
339 | 349 | ||
340 | Log.v(TAG, "Exiting communication thread"); | 350 | Log.v(TAG, "Exiting communication thread"); |
@@ -541,6 +551,8 @@ public abstract class lib3270 | @@ -541,6 +551,8 @@ public abstract class lib3270 | ||
541 | 551 | ||
542 | private int net_cleanup() | 552 | private int net_cleanup() |
543 | { | 553 | { |
554 | + connected = false; | ||
555 | +/* | ||
544 | if(sock != null) | 556 | if(sock != null) |
545 | { | 557 | { |
546 | Thread t = new Thread() | 558 | Thread t = new Thread() |
@@ -554,40 +566,26 @@ public abstract class lib3270 | @@ -554,40 +566,26 @@ public abstract class lib3270 | ||
554 | try | 566 | try |
555 | { | 567 | { |
556 | sock.shutdownInput(); | 568 | sock.shutdownInput(); |
569 | + return; | ||
557 | } | 570 | } |
558 | - catch(Exception e) | ||
559 | - { | ||
560 | - String msg = e.getLocalizedMessage(); | ||
561 | - if(msg == null) | ||
562 | - msg = e.getMessage(); | ||
563 | - | ||
564 | - Log.v(TAG,": shutdownInput error" + (msg != null ? msg : e.toString())); | ||
565 | - } | 571 | + catch(Exception e) { } |
566 | } | 572 | } |
567 | 573 | ||
568 | - /* | ||
569 | - if!(sock == null && sock.isClosed())) | 574 | + if(!(sock == null && sock.isClosed())) |
570 | { | 575 | { |
571 | try | 576 | try |
572 | { | 577 | { |
573 | sock.close(); | 578 | sock.close(); |
579 | + return; | ||
574 | } | 580 | } |
575 | - catch(Exception e) | ||
576 | - { | ||
577 | - String msg = e.getLocalizedMessage(); | ||
578 | - if(msg == null) | ||
579 | - msg = e.getMessage(); | ||
580 | - | ||
581 | - Log.v(TAG,"sockclose error: " + (msg != null ? msg : e.toString())); | ||
582 | - } | 581 | + catch(Exception e) { } |
583 | } | 582 | } |
584 | - */ | ||
585 | } | 583 | } |
586 | }; | 584 | }; |
587 | 585 | ||
588 | t.start(); | 586 | t.start(); |
589 | } | 587 | } |
590 | - | 588 | + */ |
591 | return 0; | 589 | return 0; |
592 | } | 590 | } |
593 | 591 |