This commit is contained in:
2020-08-31 14:52:28 +08:00
parent df49c40163
commit 8b1bf6c04a
6 changed files with 24 additions and 8 deletions
+5 -1
View File
@@ -18,6 +18,7 @@ use Swoole\Http\Request;
use Swoole\Http\Response;
use Exception;
use Swoole\Http\Server;
use Swoole\Process\Pool;
class Http extends Server
{
@@ -43,15 +44,18 @@ class Http extends Server
/**
* @param array $settings
* @param null $pool
* @param array $events
* @param array $config
* @return mixed|void
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception
*/
public function set(array $settings, $events = [], $config = [])
public function set(array $settings, $pool = null, $events = [], $config = [])
{
parent::set($settings);
Snowflake::get()->set(Pool::class, $pool);
ServerManager::set($this, $settings, $this->application, $events, $config);
}
+4 -1
View File
@@ -52,15 +52,18 @@ abstract class Service extends Server
/**
* @param array $settings
* @param null $pool
* @param array $events
* @param array $config
* @return mixed|void
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception
*/
public function set(array $settings, $events = [], $config = [])
public function set(array $settings, $pool = null, $events = [], $config = [])
{
parent::set($settings);
Snowflake::get()->set(Pool::class, $pool);
ServerManager::set($this, $settings, $this->application, $events, $config);
}
+9 -3
View File
@@ -10,12 +10,14 @@ namespace HttpServer\Events;
use Exception;
use HttpServer\ServerManager;
use ReflectionException;
use Snowflake\Error\Logger;
use Snowflake\Event;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
use Swoole\Http\Request as SRequest;
use Swoole\Http\Response as SResponse;
use Swoole\Process\Pool;
use Swoole\WebSocket\Frame;
use Swoole\WebSocket\Server;
@@ -50,15 +52,19 @@ class WebSocket extends Server
/**
* @param array $settings
* @param null $pool
* @param array $events
* @param $config
* @param array $config
* @return mixed|void
* @throws \ReflectionException
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception
*/
public function set(array $settings, $events = [], $config = [])
public function set(array $settings, $pool = null, $events = [], $config = [])
{
parent::set($settings);
Snowflake::get()->set(WebSocket::class, $this);
Snowflake::get()->set(Pool::class, $pool);
ServerManager::set($this, $settings, $this->application, $events, $config);
}
+1 -1
View File
@@ -26,7 +26,7 @@ class ServerManager
}
[$category, $config, $handlers, $settings] = $process;
$server = new $category[1](...static::parameter($application, $config, $category));
$server->set($settings ?? [], $handlers, $config);
$server->set($settings ?? [], $pool, $handlers, $config);
static::notice($application, $workerId, $config);
if (property_exists($server, 'pack')) {
$server->pack = $config['message']['pack'] ?? function ($data) {
+4 -1
View File
@@ -57,7 +57,6 @@ return [
],
'message' => [
'pack' => function ($data) {
var_dump($data);
return \Snowflake\Core\JSON::encode($data);
},
'unpack' => function ($data) {
@@ -86,6 +85,9 @@ return [
'receive' => function ($server, int $fd, int $reactorId, string $data) {
$server->push(1, 'success.');
$server->send($fd, 'success.');
$socket = Snowflake::get()->get(\HttpServer\Events\WebSocket::class);
$socket->push(1, 'hello word~~~~~~~~~~~~~');
},
'settings' => []
],
@@ -103,6 +105,7 @@ return [
},
Event::SERVER_MESSAGE => function (\Swoole\WebSocket\Server $server, Frame $frame) {
$this->error('websocket SERVER_MESSAGE.');
return $server->push($frame->fd, 'hello word~');
},
Event::SERVER_CLOSE => function (int $fd) {
+1 -1
View File
@@ -43,7 +43,7 @@
}
tick = setInterval(function () {
sock.send('tick');
}, 30000)
}, 3000)
}
}