Переглянути джерело

Merge remote branch 'upstream/master'

Link 6 роки тому
батько
коміт
c894fd32ef

+ 3 - 0
Connection/AsyncTcpConnection.php

@@ -318,6 +318,9 @@ class AsyncTcpConnection extends TcpConnection
             // SSL handshake.
             if ($this->transport === 'ssl') {
                 $this->_sslHandshakeCompleted = $this->doSslHandshake($this->_socket);
+                if ($this->_sslHandshakeCompleted === false) {
+                    return;
+                }
             } else {
                 // There are some data waiting to send.
                 if ($this->_sendBuffer) {

+ 5 - 1
Connection/TcpConnection.php

@@ -777,7 +777,7 @@ class TcpConnection extends ConnectionInterface
             return false;
         } elseif (0 === $ret) {
             // There isn't enough data and should try again.
-            return false;
+            return 0;
         }
         if (isset($this->onSslHandshake)) {
             try {
@@ -836,6 +836,10 @@ class TcpConnection extends ConnectionInterface
      */
     public function close($data = null, $raw = false)
     {
+        if($this->_status === self::STATUS_CONNECTING){
+            $this->destroy();
+            return;
+        }
         if ($this->_status === self::STATUS_CLOSING || $this->_status === self::STATUS_CLOSED) {
             return;
         } else {

+ 0 - 4
Lib/Constants.php

@@ -12,10 +12,6 @@
  * @license   http://www.opensource.org/licenses/mit-license.php MIT License
  */
 
-// Date.timezone
-if (!ini_get('date.timezone')) {
-    date_default_timezone_set('Asia/Shanghai');
-}
 // Display errors.
 ini_set('display_errors', 'on');
 // Reporting all.

+ 5 - 6
Protocols/Websocket.php

@@ -304,7 +304,6 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
      */
     public static function decode($buffer, ConnectionInterface $connection)
     {
-        $masks = $data = $decoded = '';
         $len = ord($buffer[1]) & 127;
         if ($len === 126) {
             $masks = substr($buffer, 4, 4);
@@ -318,9 +317,9 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
                 $data  = substr($buffer, 6);
             }
         }
-        for ($index = 0; $index < strlen($data); $index++) {
-            $decoded .= $data[$index] ^ $masks[$index % 4];
-        }
+        $dataLength = strlen($data);
+        $masks = str_repeat($masks, floor($dataLength / 4)) . substr($masks, 0, $dataLength % 4);
+        $decoded = $data ^ $masks;
         if ($connection->websocketCurrentFrameLength) {
             $connection->websocketDataBuffer .= $decoded;
             return $connection->websocketDataBuffer;
@@ -356,7 +355,7 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
             if (preg_match("/Sec-WebSocket-Key: *(.*?)\r\n/i", $buffer, $match)) {
                 $Sec_WebSocket_Key = $match[1];
             } else {
-                $connection->send("HTTP/1.1 400 Bad Request\r\n\r\n<b>400 Bad Request</b><br>Sec-WebSocket-Key not found.<br>This is a WebSocket service and can not be accessed via HTTP.<br>See <a href=\"http://wiki.workerman.net/Error1\">http://wiki.workerman.net/Error1</a> for detail.",
+                $connection->send("HTTP/1.1 200 Websocket\r\nServer: workerman/".Worker::VERSION."\r\n\r\n<div style=\"text-align:center\"><h1>Websocket</h1><hr>powerd by <a href=\"https://www.workerman.net\">workerman ".Worker::VERSION."</a></div>",
                     true);
                 $connection->close();
                 return 0;
@@ -441,7 +440,7 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
             return 0;
         }
         // Bad websocket handshake request.
-        $connection->send("HTTP/1.1 400 Bad Request\r\n\r\n<b>400 Bad Request</b><br>Invalid handshake data for websocket. <br> See <a href=\"http://wiki.workerman.net/Error1\">http://wiki.workerman.net/Error1</a> for detail.",
+        $connection->send("HTTP/1.1 200 Websocket\r\nServer: workerman/".Worker::VERSION."\r\n\r\n<div style=\"text-align:center\"><h1>Websocket</h1><hr>powerd by <a href=\"https://www.workerman.net\">workerman ".Worker::VERSION."</a></div>",
             true);
         $connection->close();
         return 0;

+ 3 - 3
Protocols/Ws.php

@@ -234,7 +234,7 @@ class Ws
         }
         $payload = (string)$payload;
         if (empty($connection->handshakeStep)) {
-            self::sendHandshake($connection);
+            static::sendHandshake($connection);
         }
         $mask = 1;
         $mask_key = "\x00\x00\x00\x00";
@@ -330,7 +330,7 @@ class Ws
      */
     public static function onConnect($connection)
     {
-        self::sendHandshake($connection);
+        static::sendHandshake($connection);
     }
 
     /**
@@ -383,7 +383,7 @@ class Ws
         (!preg_match("/\nHost:/i", $user_header_str) ? "Host: $host\r\n" : '').
         "Connection: Upgrade\r\n".
         "Upgrade: websocket\r\n".
-        "Origin: ". (isset($connection->websocketOrigin) ? $connection->websocketOrigin : '*') ."\r\n".
+        (isset($connection->websocketOrigin) ? "Origin: ".$connection->websocketOrigin."\r\n":'').
         (isset($connection->WSClientProtocol)?"Sec-WebSocket-Protocol: ".$connection->WSClientProtocol."\r\n":'').
         "Sec-WebSocket-Version: 13\r\n".
         "Sec-WebSocket-Key: " . $connection->websocketSecKey . $user_header_str . "\r\n\r\n";

+ 3 - 2
README.md

@@ -7,12 +7,13 @@
 [![License](https://poser.pugx.org/workerman/workerman/license)](https://packagist.org/packages/workerman/workerman)
 
 ## What is it
-Workerman is an asynchronous event driven PHP framework with high performance for easily building fast, scalable network applications. Supports HTTP, Websocket, SSL and other custom protocols. Supports libevent, [HHVM](https://github.com/facebook/hhvm) , [ReactPHP](https://github.com/reactphp/react).
+Workerman is an asynchronous event driven PHP framework with high performance for easily building fast, scalable network applications. Supports HTTP, Websocket, SSL and other custom protocols. Supports libevent/event extension, [HHVM](https://github.com/facebook/hhvm) , [ReactPHP](https://github.com/reactphp/react).
 
 ## Requires
 PHP 5.3 or Higher  
 A POSIX compatible operating system (Linux, OSX, BSD)  
-POSIX and PCNTL extensions for PHP  
+POSIX and PCNTL extensions required   
+Event extension recommended for better performance  
 
 ## Installation
 

+ 10 - 2
Worker.php

@@ -33,7 +33,7 @@ class Worker
      *
      * @var string
      */
-    const VERSION = '3.5.19';
+    const VERSION = '3.5.20';
 
     /**
      * Status starting.
@@ -667,6 +667,14 @@ class Worker
     {
         return static::$globalEvent;
     }
+    
+    /**
+     * Get main socket resource
+     * @return resource
+     */
+    public function getMainSocket(){
+        return $this->_mainSocket;
+    }
 
     /**
      * Init idMap.
@@ -1326,7 +1334,7 @@ class Worker
             if(count(static::$_workers) > 1)
             {
                 static::safeEcho("@@@ Error: multi workers init in one php file are not support @@@\r\n");
-                static::safeEcho("@@@ Please visit http://wiki.workerman.net/Multi_woker_for_win @@@\r\n");
+                static::safeEcho("@@@ See http://doc.workerman.net/faq/multi-woker-for-windows.html @@@\r\n");
             }
             elseif(count(static::$_workers) <= 0)
             {

+ 1 - 1
composer.json

@@ -20,7 +20,7 @@
         "email": "walkor@workerman.net",
         "issues": "https://github.com/walkor/workerman/issues",
         "forum": "http://wenda.workerman.net/",
-        "wiki": "http://doc3.workerman.net/index.html",
+        "wiki": "http://doc.workerman.net/",
         "source": "https://github.com/walkor/workerman"
     },
     "require": {