Add KCP support
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LayLink\Transport;
|
||||
|
||||
use LayLink\Protocol\Frame;
|
||||
use Workerman\Connection\UdpConnection;
|
||||
|
||||
final class KcpFrameServerConnection implements FrameServerConnection
|
||||
{
|
||||
private bool $closed = false;
|
||||
|
||||
public function __construct(
|
||||
private readonly int $id,
|
||||
private UdpConnection $connection,
|
||||
private readonly KcpReliableSession|NativeKcpSession $session,
|
||||
private readonly int $maxSendBuffer,
|
||||
) {
|
||||
}
|
||||
|
||||
public function id(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function send(Frame $frame): bool|null
|
||||
{
|
||||
if ($this->closed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->session->sendFrame($frame, $this->maxSendBuffer);
|
||||
}
|
||||
|
||||
public function close(): void
|
||||
{
|
||||
if ($this->closed) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->closed = true;
|
||||
$this->session->close();
|
||||
}
|
||||
|
||||
public function pauseRecv(): void
|
||||
{
|
||||
$this->session->pause();
|
||||
}
|
||||
|
||||
public function resumeRecv(): void
|
||||
{
|
||||
$this->session->resume();
|
||||
}
|
||||
|
||||
public function getSendBufferQueueSize(): int
|
||||
{
|
||||
return $this->session->getSendBufferQueueSize();
|
||||
}
|
||||
|
||||
public function getRemoteIp(): string
|
||||
{
|
||||
return $this->connection->getRemoteIp();
|
||||
}
|
||||
|
||||
public function updateConnection(UdpConnection $connection): void
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
public function isClosed(): bool
|
||||
{
|
||||
return $this->closed || $this->session->isClosed();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user