MCPcopy Create free account
hub / github.com/e2wugui/zeze / doHandle

Method doHandle

ZezeJava/ZezeJava/src/main/java/Zeze/Net/TcpSocket.java:184–220  ·  view source on GitHub ↗
(@NotNull SelectionKey key)

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 11

removeInterestOpsMethod · 0.95
doConnectSuccessMethod · 0.95
closeMethod · 0.95
processReceiveMethod · 0.95
doWriteMethod · 0.95
channelMethod · 0.80
OnSocketAcceptErrorMethod · 0.80
acceptMethod · 0.65
closeMethod · 0.65
getServiceMethod · 0.45
OnSocketConnectErrorMethod · 0.45

Tested by

no test coverage detected