瀏覽代碼

update mac project

shjung 1 天之前
父節點
當前提交
f0cfdbf0f2
共有 1 個文件被更改,包括 19 次插入4 次删除
  1. 19 4
      src/main/java/com/its/dsrc/xnettcp/center/CenterTcpServerService.java

+ 19 - 4
src/main/java/com/its/dsrc/xnettcp/center/CenterTcpServerService.java

@@ -66,13 +66,21 @@ public class CenterTcpServerService {
 
         try {
             if (this.config.getBindingAddr().equals("0.0.0.0")) {
-                this.channelFuture = serverBootstrap.bind(this.config.getListenPort());
+                this.channelFuture = serverBootstrap.bind(this.config.getListenPort()).sync();
             }
             else {
-                this.channelFuture = serverBootstrap.bind(this.config.getBindingAddr(), config.getListenPort());
+                this.channelFuture = serverBootstrap.bind(this.config.getBindingAddr(), config.getListenPort()).sync();
             }
-        }
-        catch (Exception e) {
+            if (!this.channelFuture.isSuccess()) {
+                log.error("CenterTcpServerService bind failed: {}", channelFuture.cause().getMessage());
+            }
+
+        } catch (InterruptedException ie) {
+            Thread.currentThread().interrupt();
+            log.error("CenterTcpServerService bind InterruptedException: {}", ie.getMessage());
+            if (this.acceptGroups != null) this.acceptGroups.shutdownGracefully();
+            if (this.workerGroups != null) this.workerGroups.shutdownGracefully();
+        } catch (Exception e) {
             log.error("CenterTcpServerService bind exception: {}", e.getMessage());
             if (this.acceptGroups != null) this.acceptGroups.shutdownGracefully();
             if (this.workerGroups != null) this.workerGroups.shutdownGracefully();
@@ -81,14 +89,21 @@ public class CenterTcpServerService {
 
     public void stop() {
         try {
+            if (this.channelFuture != null && this.channelFuture.channel() != null) {
+                this.channelFuture.channel().close().sync();
+                this.channelFuture = null;
+            }
             if (this.acceptGroups != null) {
                 this.acceptGroups.shutdownGracefully().sync();
+                this.acceptGroups = null;
             }
             if (this.workerGroups != null) {
                 this.workerGroups.shutdownGracefully().sync();
+                this.workerGroups = null;
             }
 //            if (this.channelFuture != null && this.channelFuture.channel() != null) {
 //                this.channelFuture.channel().closeFuture().sync();
+//                this.channelFuture = null;
 //            }
         }
         catch (InterruptedException e) {