Skip to content

Commit

Permalink
修正options配置无效问题.
Browse files Browse the repository at this point in the history
  • Loading branch information
LonelySally committed Sep 9, 2020
1 parent b64724a commit d94bf39
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
8 changes: 0 additions & 8 deletions src/concerns/InteractsWithServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ trait InteractsWithServer
*/
public function run(): void
{
$this->getServer()->set([
'task_enable_coroutine' => true,
'send_yield' => true,
'reload_async' => true,
'enable_coroutine' => true,
'max_request' => 0,
'task_max_request' => 0,
]);
$this->initialize();
$this->triggerEvent('init');

Expand Down
6 changes: 6 additions & 0 deletions src/config/swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
'package_max_length' => 20 * 1024 * 1024,
'buffer_output_size' => 10 * 1024 * 1024,
'socket_buffer_size' => 128 * 1024 * 1024,
'task_enable_coroutine' => true,
'send_yield' => true,
'reload_async' => true,
'enable_coroutine' => true,
'task_max_request' => 1000,
'max_request' => 1000,
],
],
'websocket' => [
Expand Down
2 changes: 1 addition & 1 deletion src/websocket/Pusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected function getWebsocketConnections(): array
*/
protected function shouldPushToDescriptor(int $fd): bool
{
if (!$this->server->exist($fd)) {
if (!$this->server->isEstablished($fd)) {
return false;
}

Expand Down
23 changes: 12 additions & 11 deletions src/websocket/socketio/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@ public function __construct(Server $server, Config $config)
/**
* "onOpen" listener.
*
* @param int $fd
* @param int $fd
* @param Request $request
*/
public function onOpen($fd, Request $request)
{
if (!$request->param('sid')) {
$payload = json_encode(
$payload = json_encode(
[
'sid' => base64_encode(uniqid()),
'upgrades' => [],
'sid' => base64_encode(uniqid()),
'upgrades' => [],
'pingInterval' => $this->config->get('swoole.websocket.ping_interval'),
'pingTimeout' => $this->config->get('swoole.websocket.ping_timeout'),
'pingTimeout' => $this->config->get('swoole.websocket.ping_timeout'),
]
);
$initPayload = Packet::OPEN . $payload;
$initPayload = Packet::OPEN . $payload;
$connectPayload = Packet::MESSAGE . Packet::CONNECT;

$this->server->push($fd, $initPayload);
$this->server->push($fd, $connectPayload);
if ($this->server->isEstablished($fd)) {
$this->server->push($fd, $initPayload);
$this->server->push($fd, $connectPayload);
}
}
}

Expand Down Expand Up @@ -81,7 +82,7 @@ public function onClose($fd, $reactorId)
protected function checkHeartbeat($fd, $packet)
{
$packetLength = strlen($packet);
$payload = '';
$payload = '';

if ($isPing = Packet::isSocketType($packet, 'ping')) {
$payload .= Packet::PONG;
Expand All @@ -91,7 +92,7 @@ protected function checkHeartbeat($fd, $packet)
$payload .= substr($packet, 1, $packetLength - 1);
}

if ($isPing) {
if ($isPing && $this->server->isEstablished($fd)) {
$this->server->push($fd, $payload);
}
}
Expand Down

0 comments on commit d94bf39

Please sign in to comment.