This commit is contained in:
2021-09-09 17:17:44 +08:00
parent 9ca2d6634d
commit 9a5aebcfd2
7 changed files with 33 additions and 15 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Server\Constrict; namespace Server\Constrict;
use Psr\Http\Message\ResponseInterface; use Server\ResponseInterface;
interface Emitter interface Emitter
{ {
+18
View File
@@ -307,4 +307,22 @@ class Response implements ResponseInterface
{ {
return $this->__call__()->{__FUNCTION__}(); return $this->__call__()->{__FUNCTION__}();
} }
/**
* @return int
*/
public function getClientId(): int
{
return $this->__call__()->{__FUNCTION__}();
}
/**
* @return array
*/
public function getClientInfo(): array
{
return $this->__call__()->{__FUNCTION__}();
}
} }
+1 -1
View File
@@ -3,7 +3,7 @@
namespace Server\Constrict; namespace Server\Constrict;
use Annotation\Inject; use Annotation\Inject;
use Psr\Http\Message\ResponseInterface; use Server\ResponseInterface;
use Server\RequestInterface; use Server\RequestInterface;
use Server\SInterface\DownloadInterface; use Server\SInterface\DownloadInterface;
use Swoole\Server; use Swoole\Server;
+6 -8
View File
@@ -2,9 +2,9 @@
namespace Server\Constrict; namespace Server\Constrict;
use Exception;
use Http\Context\Formatter\FileFormatter; use Http\Context\Formatter\FileFormatter;
use Kiri\Exception\NotFindClassException; use Server\ResponseInterface;
use Psr\Http\Message\ResponseInterface;
use Swoole\Server; use Swoole\Server;
@@ -18,17 +18,15 @@ class TcpEmitter implements Emitter
/** /**
* @param Server $response * @param Server $response
* @param ResponseInterface $emitter * @param ResponseInterface $emitter
* @throws NotFindClassException * @throws Exception
* @throws \ReflectionException
* @throws \Exception
*/ */
public function sender(mixed $response, ResponseInterface $emitter): void public function sender(mixed $response, ResponseInterface $emitter): void
{ {
$formatter = $emitter->getContent(); $formatter = $emitter->stream->getContents();
if ($formatter instanceof FileFormatter) { if ($formatter instanceof FileFormatter) {
$response->sendfile($emitter->getClientId(), $formatter->getData()); $response->sendfile($emitter->getClientId(), $formatter);
} else { } else {
$response->send($emitter->getClientId(), $formatter->getData()); $response->send($emitter->getClientId(), $formatter);
} }
} }
} }
+2 -4
View File
@@ -3,7 +3,7 @@
namespace Server\Constrict; namespace Server\Constrict;
use Kiri\Exception\NotFindClassException; use Kiri\Exception\NotFindClassException;
use Psr\Http\Message\ResponseInterface; use Server\ResponseInterface;
use Swoole\Server; use Swoole\Server;
@@ -17,15 +17,13 @@ class UdpEmitter implements Emitter
/** /**
* @param Server $response * @param Server $response
* @param ResponseInterface $emitter * @param ResponseInterface $emitter
* @throws NotFindClassException
* @throws \ReflectionException
* @throws \Exception * @throws \Exception
*/ */
public function sender(mixed $response, ResponseInterface $emitter): void public function sender(mixed $response, ResponseInterface $emitter): void
{ {
$clientInfo = $emitter->getClientInfo(); $clientInfo = $emitter->getClientInfo();
$response->sendto($clientInfo['host'], $clientInfo['port'], $response->sendto($clientInfo['host'], $clientInfo['port'],
$emitter->getContent()->getData() $emitter->stream->getContents()
); );
} }
} }
+1 -1
View File
@@ -5,8 +5,8 @@ namespace Server\Constrict;
use Exception; use Exception;
use Kiri\Kiri; use Kiri\Kiri;
use Psr\Http\Message\ResponseInterface;
use Server\ServerManager; use Server\ServerManager;
use Server\ResponseInterface;
/** /**
* *
+4
View File
@@ -21,6 +21,10 @@ interface ResponseInterface extends \Psr\Http\Message\ResponseInterface
public function file(string $path): DownloadInterface; public function file(string $path): DownloadInterface;
public function getClientId(): int;
public function getClientInfo(): array;
/** /**
* @param $responseData * @param $responseData
* @return string|array|bool|int|null * @return string|array|bool|int|null