소스 검색

connection count of static

walkor 10 년 전
부모
커밋
11edd5798c
2개의 변경된 파일10개의 추가작업 그리고 4개의 파일을 삭제
  1. 5 2
      Workerman/Connection/AsyncTcpConnection.php
  2. 5 2
      Workerman/Connection/TcpConnection.php

+ 5 - 2
Workerman/Connection/AsyncTcpConnection.php

@@ -50,6 +50,8 @@ class AsyncTcpConnection extends TcpConnection
         }
         $this->_remoteAddress = substr($address, 2);
         $this->id = self::$_idRecorder++;
+        // 统计数据
+        self::$statistics['connection_count']++;
     }
     
     public function connect()
@@ -110,8 +112,6 @@ class AsyncTcpConnection extends TcpConnection
             }
             // 标记状态为连接已经建立
             $this->_status = self::STATUS_ESTABLISH;
-            // 为status 命令统计数据
-            ConnectionInterface::$statistics['connection_count']++;
             // 如果有设置onConnect回调,则执行
             if($this->onConnect)
             {
@@ -128,6 +128,9 @@ class AsyncTcpConnection extends TcpConnection
         }
         else
         {
+            $this->_status = self::STATUS_CLOSED;
+            // 关闭socket
+            @fclose($this->_socket);
             // 连接未建立成功
             $this->emitError(WORKERMAN_CONNECT_FAIL, 'connect fail');
         }

+ 5 - 2
Workerman/Connection/TcpConnection.php

@@ -576,7 +576,7 @@ class TcpConnection extends ConnectionInterface
     }
     /**
      * 销毁连接
-     * @void
+     * @return void
      */
     public function destroy()
     {
@@ -590,7 +590,6 @@ class TcpConnection extends ConnectionInterface
         Worker::$globalEvent->del($this->_socket, EventInterface::EV_WRITE);
         // 关闭socket
         @fclose($this->_socket);
-        
         // 从连接中删除
         if($this->worker)
         {
@@ -613,6 +612,10 @@ class TcpConnection extends ConnectionInterface
        }
     }
     
+    /**
+     * 析构函数
+     * @return void
+     */
     public function __destruct()
     {
         // 统计数据