walkor 4 years ago
parent
commit
6b4c890ac4
3 changed files with 11 additions and 34 deletions
  1. 1 1
      Connection/AsyncTcpConnection.php
  2. 1 24
      Connection/TcpConnection.php
  3. 9 9
      Worker.php

+ 1 - 1
Connection/AsyncTcpConnection.php

@@ -352,7 +352,7 @@ class AsyncTcpConnection extends TcpConnection
                 }
             }
             // Try to emit protocol::onConnect
-            if (\is_callable($this->protocol, 'onConnect')) {
+            if ($this->protocol && \method_exists($this->protocol, 'onConnect')) {
                 try {
                     \call_user_func(array($this->protocol, 'onConnect'), $this);
                 } catch (\Exception $e) {

+ 1 - 24
Connection/TcpConnection.php

@@ -261,29 +261,6 @@ class TcpConnection extends ConnectionInterface
         self::STATUS_CLOSED      => 'CLOSED',
     );
 
-
-    /**
-     * Adding support of custom functions within protocols
-     *
-     * @param string $name
-     * @param array  $arguments
-     * @return void
-     */
-    public function __call($name, array $arguments) {
-        // Try to emit custom function within protocol
-        if (\is_callable($this->protocol, $name)) {
-            try {
-                return \call_user_func(array($this->protocol, $name), $this, $arguments);
-            } catch (\Exception $e) {
-                Worker::log($e);
-                exit(250);
-            } catch (\Error $e) {
-                Worker::log($e);
-                exit(250);
-            }
-        }
-    }
-
     /**
      * Construct.
      *
@@ -961,7 +938,7 @@ class TcpConnection extends ConnectionInterface
             }
         }
         // Try to emit protocol::onClose
-        if ($this->protocol && \is_callable($this->protocol, 'onClose')) {
+        if ($this->protocol && \method_exists($this->protocol, 'onClose')) {
             try {
                 \call_user_func(array($this->protocol, 'onClose'), $this);
             } catch (\Exception $e) {

+ 9 - 9
Worker.php

@@ -2526,27 +2526,27 @@ class Worker
             try {
                 if ($this->protocol !== null) {
                     /** @var \Workerman\Protocols\ProtocolInterface $parser */
-                    $parser      = $this->protocol;
-                    if(\is_callable($parser,'input')){
-                        while($recv_buffer !== ''){
+                    $parser = $this->protocol;
+                    if ($parser && \method_exists($parser, 'input')) {
+                        while ($recv_buffer !== '') {
                             $len = $parser::input($recv_buffer, $connection);
-                            if($len === 0)
+                            if ($len === 0)
                                 return true;
-                            $package = \substr($recv_buffer,0,$len);
-                            $recv_buffer = \substr($recv_buffer,$len);
-                            $data = $parser::decode($package,$connection);
+                            $package = \substr($recv_buffer, 0, $len);
+                            $recv_buffer = \substr($recv_buffer, $len);
+                            $data = $parser::decode($package, $connection);
                             if ($data === false)
                                 continue;
                             \call_user_func($this->onMessage, $connection, $data);
                         }
-                    }else{
+                    } else {
                         $data = $parser::decode($recv_buffer, $connection);
                         // Discard bad packets.
                         if ($data === false)
                             return true;
                         \call_user_func($this->onMessage, $connection, $data);
                     }
-                }else{
+                } else {
                     \call_user_func($this->onMessage, $connection, $recv_buffer);
                 }
                 ++ConnectionInterface::$statistics['total_request'];