equal
deleted
inserted
replaced
43 * not implement any security checks. |
43 * not implement any security checks. |
44 * Note this class should <b>NOT</b> be public. |
44 * Note this class should <b>NOT</b> be public. |
45 * |
45 * |
46 * @author Steven B. Byrne |
46 * @author Steven B. Byrne |
47 */ |
47 */ |
48 abstract class AbstractPlainSocketImpl extends SocketImpl |
48 abstract class AbstractPlainSocketImpl extends SocketImpl { |
49 { |
|
50 /* instance variable for SO_TIMEOUT */ |
49 /* instance variable for SO_TIMEOUT */ |
51 int timeout; // timeout in millisec |
50 int timeout; // timeout in millisec |
52 // traffic class |
51 // traffic class |
53 private int trafficClass; |
52 private int trafficClass; |
54 |
53 |
66 |
65 |
67 /* indicates a close is pending on the file descriptor */ |
66 /* indicates a close is pending on the file descriptor */ |
68 protected boolean closePending = false; |
67 protected boolean closePending = false; |
69 |
68 |
70 /* indicates connection reset state */ |
69 /* indicates connection reset state */ |
71 private int CONNECTION_NOT_RESET = 0; |
70 private volatile boolean connectionReset; |
72 private int CONNECTION_RESET_PENDING = 1; |
|
73 private int CONNECTION_RESET = 2; |
|
74 private int resetState; |
|
75 private final Object resetLock = new Object(); |
|
76 |
71 |
77 /* whether this Socket is a stream (TCP) socket or not (UDP) |
72 /* whether this Socket is a stream (TCP) socket or not (UDP) |
78 */ |
73 */ |
79 protected boolean stream; |
74 protected boolean stream; |
80 |
75 |
539 * again if there are bytes buffered on the socket. |
534 * again if there are bytes buffered on the socket. |
540 */ |
535 */ |
541 int n = 0; |
536 int n = 0; |
542 try { |
537 try { |
543 n = socketAvailable(); |
538 n = socketAvailable(); |
544 if (n == 0 && isConnectionResetPending()) { |
|
545 setConnectionReset(); |
|
546 } |
|
547 } catch (ConnectionResetException exc1) { |
539 } catch (ConnectionResetException exc1) { |
548 setConnectionResetPending(); |
540 setConnectionReset(); |
549 try { |
|
550 n = socketAvailable(); |
|
551 if (n == 0) { |
|
552 setConnectionReset(); |
|
553 } |
|
554 } catch (ConnectionResetException exc2) { |
|
555 } |
|
556 } |
541 } |
557 return n; |
542 return n; |
558 } |
543 } |
559 |
544 |
560 /** |
545 /** |
678 } |
663 } |
679 } |
664 } |
680 } |
665 } |
681 } |
666 } |
682 |
667 |
683 public boolean isConnectionReset() { |
668 boolean isConnectionReset() { |
684 synchronized (resetLock) { |
669 return connectionReset; |
685 return (resetState == CONNECTION_RESET); |
670 } |
686 } |
671 |
687 } |
672 void setConnectionReset() { |
688 |
673 connectionReset = true; |
689 public boolean isConnectionResetPending() { |
|
690 synchronized (resetLock) { |
|
691 return (resetState == CONNECTION_RESET_PENDING); |
|
692 } |
|
693 } |
|
694 |
|
695 public void setConnectionReset() { |
|
696 synchronized (resetLock) { |
|
697 resetState = CONNECTION_RESET; |
|
698 } |
|
699 } |
|
700 |
|
701 public void setConnectionResetPending() { |
|
702 synchronized (resetLock) { |
|
703 if (resetState == CONNECTION_NOT_RESET) { |
|
704 resetState = CONNECTION_RESET_PENDING; |
|
705 } |
|
706 } |
|
707 |
|
708 } |
674 } |
709 |
675 |
710 /* |
676 /* |
711 * Return true if already closed or close is pending |
677 * Return true if already closed or close is pending |
712 */ |
678 */ |