فهرست منبع

unlink unix domain file && add protocol::encode for udp

walkor 9 سال پیش
والد
کامیت
d7bbca40b6
3فایلهای تغییر یافته به همراه18 افزوده شده و 2 حذف شده
  1. 1 1
      Connection/TcpConnection.php
  2. 11 1
      Connection/UdpConnection.php
  3. 6 0
      Worker.php

+ 1 - 1
Connection/TcpConnection.php

@@ -187,7 +187,7 @@ class TcpConnection extends ConnectionInterface
      * @param resource $socket
      * @param EventInterface $event
      */
-    public function __construct($socket, $remote_address)
+    public function __construct($socket, $remote_address = '')
     {
         // 统计数据
         self::$statistics['connection_count']++;

+ 11 - 1
Connection/UdpConnection.php

@@ -66,8 +66,18 @@ class UdpConnection extends ConnectionInterface
      * @param string $send_buffer
      * @return void|boolean
      */
-    public function send($send_buffer)
+    public function send($send_buffer, $raw = false)
     {
+        // 如果没有设置以原始数据发送,并且有设置协议则按照协议编码
+        if(false === $raw && $this->protocol)
+        {
+            $parser = $this->protocol;
+            $send_buffer = $parser::encode($send_buffer, $this);
+            if($send_buffer === '')
+            {
+                return null;
+            }
+        }
         return strlen($send_buffer) === stream_socket_sendto($this->_socket, $send_buffer, 0, $this->_remoteAddress);
     }
     

+ 6 - 0
Worker.php

@@ -1032,6 +1032,11 @@ class Worker
      */
     protected static function exitAndClearAll()
     {
+        if($this->transport === 'unix' && $this->_socketName)
+        {
+            list(, $address) = explode(':', $this->_socketName, 2);
+            @unlink($address);
+        }
         @unlink(self::$pidFile);
         self::log("Workerman[".basename(self::$_startFile)."] has been stopped");
         exit(0);
@@ -1355,6 +1360,7 @@ class Worker
         if($this->transport === 'unix')
         {
             umask(0);
+            list($scheme, $address) = explode(':', $this->_socketName, 2);
             if(!is_file($address))
             {
                 register_shutdown_function(function()use($address){@unlink($address);});