(@NotNull SelectionKey key)
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public void doHandle(@NotNull SelectionKey key) throws Exception { |
| 186 | SelectableChannel channel = key.channel(); |
| 187 | int ops = key.readyOps(); |
| 188 | if ((ops & SelectionKey.OP_ACCEPT) != 0) { |
| 189 | SocketChannel sc = null; |
| 190 | try { |
| 191 | sc = ((ServerSocketChannel)channel).accept(); |
| 192 | if (sc != null) |
| 193 | new TcpSocket(getService(), sc, (Acceptor)acceptorOrConnector); |
| 194 | } catch (Exception e) { |
| 195 | if (sc != null) |
| 196 | sc.close(); |
| 197 | getService().OnSocketAcceptError(this, e); |
| 198 | return; |
| 199 | } |
| 200 | } else if ((ops & SelectionKey.OP_CONNECT) != 0) { |
| 201 | try { |
| 202 | SocketChannel sc = (SocketChannel)channel; |
| 203 | if (!sc.finishConnect()) |
| 204 | throw connectFailedException; |
| 205 | // 先修改事件,防止doConnectSuccess发送数据注册了新的事件导致OP_CONNECT重新触发。 |
| 206 | // 虽然实际上在回调中应该不会唤醒Selector重入。 |
| 207 | removeInterestOps(SelectionKey.OP_CONNECT); |
| 208 | doConnectSuccess(sc); |
| 209 | } catch (Exception e) { |
| 210 | close(e); // if OnSocketConnectError throw Exception, this will close in doException |
| 211 | getService().OnSocketConnectError(this, e); |
| 212 | return; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | if ((ops & SelectionKey.OP_READ) != 0) |
| 217 | processReceive((SocketChannel)channel); |
| 218 | if ((ops & SelectionKey.OP_WRITE) != 0) |
| 219 | doWrite((SocketChannel)channel); |
| 220 | } |
| 221 | |
| 222 | @Override |
| 223 | public void doException(@NotNull SelectionKey key, @NotNull Throwable e) { |
nothing calls this directly
no test coverage detected