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

Method TcpSocket

ZezeJava/ZezeJava/src/main/java/Zeze/Net/TcpSocket.java:143–182  ·  view source on GitHub ↗

for server socket

(@NotNull Service service, @Nullable InetSocketAddress localEP, @Nullable Acceptor acceptor)

Source from the content-addressed store, hash-verified

141 * for server socket
142 */
143 public TcpSocket(@NotNull Service service, @Nullable InetSocketAddress localEP, @Nullable Acceptor acceptor) {
144 super(service);
145
146 this.acceptorOrConnector = acceptor;
147 this.type = Type.eServerSocket;
148 service.tryStartKeepAliveCheckTimer();
149
150 ServerSocketChannel ssc = null;
151 try {
152 ssc = ServerSocketChannel.open();
153 ssc.configureBlocking(false);
154 ServerSocket ss = ssc.socket();
155 ss.setReuseAddress(true);
156 // xxx 只能设置到 ServerSocket 中,以后 Accept 的连接通过继承机制得到这个配置。
157 Integer recvBufSize = service.getSocketOptions().getReceiveBuffer();
158 if (recvBufSize != null)
159 ss.setReceiveBufferSize(recvBufSize);
160 ss.bind(localEP, service.getSocketOptions().getBacklog());
161 service.onServerSocketBind(ss);
162 logger.info("Listen: [{}] {} for {}:{}", getSessionId(), localEP, service.getClass().getName(), service.getName());
163
164 timeThrottle = null;
165 selector = service.getSelectors().choice();
166 operates = null;
167 inputBuffer = null;
168 outputBuffer = null;
169 selectionKey = selector.register(ssc, 0, this); // 先获取key,因为有小概率出现事件处理比赋值更先执行
170 addInterestOps(SelectionKey.OP_ACCEPT);
171 selector.wakeup();
172 } catch (IOException e) {
173 if (ssc != null) {
174 try {
175 ssc.close();
176 } catch (Exception ex) {
177 logger.error("ServerSocketChannel.close exception:", ex);
178 }
179 }
180 throw new IllegalStateException("bind " + localEP, e);
181 }
182 }
183
184 @Override
185 public void doHandle(@NotNull SelectionKey key) throws Exception {

Callers

nothing calls this directly

Calls 15

addInterestOpsMethod · 0.95
createMethod · 0.95
doConnectSuccessMethod · 0.95
forceThrowMethod · 0.95
getReceiveBufferMethod · 0.80
getBacklogMethod · 0.80
choiceMethod · 0.80
getSendBufferMethod · 0.80
getNoDelayMethod · 0.80
openMethod · 0.65

Tested by

no test coverage detected