74 private volatile boolean isOutputClosed;
75
76 private boolean isReuseAddress;
77
78 private static final int ST_UNCONNECTED = 0;
79 private static final int ST_CONNECTIONPENDING = 1;
80 private static final int ST_CONNECTED = 2;
81 private static final int ST_CLOSING = 3;
82 private static final int ST_KILLPENDING = 4;
83 private static final int ST_KILLED = 5;
84 private volatile int state; // need stateLock to change
85
86 private long readerThread;
87 private long writerThread;
88
89 private InetSocketAddress localAddress;
90 private InetSocketAddress remoteAddress;
91
92 private Socket socket;
93
94 protected RdmaSocketChannelImpl(SelectorProvider sp) throws IOException {
95 super(sp);
96 this.fd = RdmaNet.socket();
97 this.fdVal = IOUtil.fdVal(fd);
98 }
99
100 protected RdmaSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, boolean bound)
101 throws IOException
102 {
103 super(sp);
104 this.fd = fd;
105 this.fdVal = IOUtil.fdVal(fd);
106 if (bound) {
107 synchronized (stateLock) {
108 this.localAddress = RdmaNet.localAddress(fd);
109 }
110 }
111 }
112
113 RdmaSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, InetSocketAddress isa)
114 throws IOException
115 {
116 super(sp);
117 this.fd = fd;
118 this.fdVal = IOUtil.fdVal(fd);
119 synchronized (stateLock) {
120 this.localAddress = RdmaNet.localAddress(fd);
121 this.remoteAddress = isa;
122 this.state = ST_CONNECTED;
123 }
124 }
125
126 private void ensureOpen() throws ClosedChannelException {
127 if (!isOpen())
128 throw new ClosedChannelException();
129 }
130
131 private void ensureOpenAndConnected() throws ClosedChannelException {
132 int state = this.state;
133 if (state < ST_CONNECTED) {
134 throw new NotYetConnectedException();
135 } else if (state > ST_CONNECTED) {
136 throw new ClosedChannelException();
929 sb.append(" oshut");
930 break;
931 }
932 InetSocketAddress addr = localAddress();
933 if (addr != null) {
934 sb.append(" local=");
935 sb.append(Net.getRevealedLocalAddressAsString(addr));
936 }
937 if (remoteAddress() != null) {
938 sb.append(" remote=");
939 sb.append(remoteAddress().toString());
940 }
941 }
942 }
943 sb.append(']');
944 return sb.toString();
945 }
946
947 // -- Native methods --
948
949 private static native void initIDs();
950
951 private static native int checkConnect(FileDescriptor fd, boolean block)
952 throws IOException;
953
954 private static native int sendOutOfBandData(FileDescriptor fd, byte data)
955 throws IOException;
956
957 static {
958 IOUtil.load();
959 System.loadLibrary("extnet");
960 initIDs();
961 nd = new RdmaSocketDispatcher();
962 }
963
964 }
|
74 private volatile boolean isOutputClosed;
75
76 private boolean isReuseAddress;
77
78 private static final int ST_UNCONNECTED = 0;
79 private static final int ST_CONNECTIONPENDING = 1;
80 private static final int ST_CONNECTED = 2;
81 private static final int ST_CLOSING = 3;
82 private static final int ST_KILLPENDING = 4;
83 private static final int ST_KILLED = 5;
84 private volatile int state; // need stateLock to change
85
86 private long readerThread;
87 private long writerThread;
88
89 private InetSocketAddress localAddress;
90 private InetSocketAddress remoteAddress;
91
92 private Socket socket;
93
94 private static final UnsupportedOperationException unsupported;
95
96 private static final SelectorProvider checkSupported(SelectorProvider sp) {
97 if (unsupported != null)
98 throw new UnsupportedOperationException(unsupported.getMessage(), unsupported);
99 else
100 return sp;
101 }
102
103 protected RdmaSocketChannelImpl(SelectorProvider sp) throws IOException {
104 super(checkSupported(sp));
105 this.fd = RdmaNet.socket();
106 this.fdVal = IOUtil.fdVal(fd);
107 }
108
109 protected RdmaSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, boolean bound)
110 throws IOException
111 {
112 super(checkSupported(sp));
113 this.fd = fd;
114 this.fdVal = IOUtil.fdVal(fd);
115 if (bound) {
116 synchronized (stateLock) {
117 this.localAddress = RdmaNet.localAddress(fd);
118 }
119 }
120 }
121
122 RdmaSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, InetSocketAddress isa)
123 throws IOException
124 {
125 super(checkSupported(sp));
126 this.fd = fd;
127 this.fdVal = IOUtil.fdVal(fd);
128 synchronized (stateLock) {
129 this.localAddress = RdmaNet.localAddress(fd);
130 this.remoteAddress = isa;
131 this.state = ST_CONNECTED;
132 }
133 }
134
135 private void ensureOpen() throws ClosedChannelException {
136 if (!isOpen())
137 throw new ClosedChannelException();
138 }
139
140 private void ensureOpenAndConnected() throws ClosedChannelException {
141 int state = this.state;
142 if (state < ST_CONNECTED) {
143 throw new NotYetConnectedException();
144 } else if (state > ST_CONNECTED) {
145 throw new ClosedChannelException();
938 sb.append(" oshut");
939 break;
940 }
941 InetSocketAddress addr = localAddress();
942 if (addr != null) {
943 sb.append(" local=");
944 sb.append(Net.getRevealedLocalAddressAsString(addr));
945 }
946 if (remoteAddress() != null) {
947 sb.append(" remote=");
948 sb.append(remoteAddress().toString());
949 }
950 }
951 }
952 sb.append(']');
953 return sb.toString();
954 }
955
956 // -- Native methods --
957
958 private static native void initIDs() throws UnsupportedOperationException;
959
960 private static native int checkConnect(FileDescriptor fd, boolean block)
961 throws IOException;
962
963 private static native int sendOutOfBandData(FileDescriptor fd, byte data)
964 throws IOException;
965
966 static {
967 IOUtil.load();
968 System.loadLibrary("extnet");
969 UnsupportedOperationException uoe = null;
970 try {
971 initIDs();
972 } catch (UnsupportedOperationException e) {
973 uoe = e;
974 }
975 unsupported = uoe;
976 nd = new RdmaSocketDispatcher();
977 }
978
979 }
|