Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
linkec committed Jul 27, 2019
2 parents 9e14e37 + e8415bb commit c894fd3
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Connection/AsyncTcpConnection.php
Expand Up @@ -318,6 +318,9 @@ public function checkConnection()
// 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) {
Expand Down
6 changes: 5 additions & 1 deletion Connection/TcpConnection.php
Expand Up @@ -777,7 +777,7 @@ public function doSslHandshake($socket){
return false;
} elseif (0 === $ret) {
// There isn't enough data and should try again.
return false;
return 0;
}
if (isset($this->onSslHandshake)) {
try {
Expand Down Expand Up @@ -836,6 +836,10 @@ public function consumeRecvBuffer($length)
*/
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 {
Expand Down
4 changes: 0 additions & 4 deletions Lib/Constants.php
Expand Up @@ -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.
Expand Down
11 changes: 5 additions & 6 deletions Protocols/Websocket.php
Expand Up @@ -304,7 +304,6 @@ public static function encode($buffer, ConnectionInterface $connection)
*/
public static function decode($buffer, ConnectionInterface $connection)
{
$masks = $data = $decoded = '';
$len = ord($buffer[1]) & 127;
if ($len === 126) {
$masks = substr($buffer, 4, 4);
Expand All @@ -318,9 +317,9 @@ public static function decode($buffer, ConnectionInterface $connection)
$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;
Expand Down Expand Up @@ -356,7 +355,7 @@ protected static function dealHandshake($buffer, $connection)
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;
Expand Down Expand Up @@ -441,7 +440,7 @@ protected static function dealHandshake($buffer, $connection)
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;
Expand Down
6 changes: 3 additions & 3 deletions Protocols/Ws.php
Expand Up @@ -234,7 +234,7 @@ public static function encode($payload, $connection)
}
$payload = (string)$payload;
if (empty($connection->handshakeStep)) {
self::sendHandshake($connection);
static::sendHandshake($connection);
}
$mask = 1;
$mask_key = "\x00\x00\x00\x00";
Expand Down Expand Up @@ -330,7 +330,7 @@ public static function decode($bytes, $connection)
*/
public static function onConnect($connection)
{
self::sendHandshake($connection);
static::sendHandshake($connection);
}

/**
Expand Down Expand Up @@ -383,7 +383,7 @@ public static function sendHandshake($connection)
(!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";
Expand Down
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions Worker.php
Expand Up @@ -33,7 +33,7 @@ class Worker
*
* @var string
*/
const VERSION = '3.5.19';
const VERSION = '3.5.20';

/**
* Status starting.
Expand Down Expand Up @@ -667,6 +667,14 @@ public static function getEventLoop()
{
return static::$globalEvent;
}

/**
* Get main socket resource
* @return resource
*/
public function getMainSocket(){
return $this->_mainSocket;
}

/**
* Init idMap.
Expand Down Expand Up @@ -1326,7 +1334,7 @@ protected static function forkWorkersForWindows()
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)
{
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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": {
Expand Down

0 comments on commit c894fd3

Please sign in to comment.