Skip to content

Commit

Permalink
Pre-release: updated copyrighted content
Browse files Browse the repository at this point in the history
  • Loading branch information
cclilshy committed Nov 13, 2024
1 parent 7e72a9e commit 36791c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
11 changes: 5 additions & 6 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
namespace Ripple\WebSocket;

use Closure;
use Co\IO;
use Exception;
use Ripple\Socket\SocketStream;
use Ripple\Socket;
use Ripple\Stream;
use Ripple\Stream\Exception\ConnectionException;
use Ripple\Utils\Output;
Expand Down Expand Up @@ -92,9 +91,9 @@ class Client
private Closure $onError;

/**
* @var SocketStream
* @var Socket
*/
private SocketStream $stream;
private Socket $stream;

/**
* @var string
Expand Down Expand Up @@ -161,8 +160,8 @@ private function handshake(): void
$path = $parsedUrl['path'] ?? '';
$path = $path !== '' ? $path : '/';
$this->stream = match ($scheme) {
'ws' => IO::Socket()->connect("tcp://{$host}:{$port}", $this->timeout, $this->context),
'wss' => IO::Socket()->connectWithSSL("ssl://{$host}:{$port}", $this->timeout, $this->context),
'ws' => Socket::connect("tcp://{$host}:{$port}", $this->timeout, $this->context),
'wss' => Socket::connectWithSSL("ssl://{$host}:{$port}", $this->timeout, $this->context),
default => throw new Exception('Unsupported scheme'),
};

Expand Down
11 changes: 5 additions & 6 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
namespace Ripple\WebSocket;

use Closure;
use Co\IO;
use Ripple\Kernel;
use Ripple\Socket\SocketStream;
use Ripple\Socket;
use Ripple\Stream\Exception\RuntimeException;
use Ripple\WebSocket\Server\Connection;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -71,8 +70,8 @@ class Server
/*** @var Closure */
private Closure $onRequest;

/*** @var SocketStream */
private SocketStream $server;
/*** @var Socket */
private Socket $server;

/*** @var Options */
private Options $options;
Expand Down Expand Up @@ -104,7 +103,7 @@ public function __construct(string $address, mixed $context = null, Options|null
throw new RuntimeException('The address must contain a port');
}

$this->server = IO::Socket()->server("tcp://{$host}:{$port}", $context);
$this->server = Socket::server("tcp://{$host}:{$port}", $context);

$this->server->setOption(SOL_SOCKET, SO_KEEPALIVE, 1);
$this->server->setOption(SOL_SOCKET, SO_REUSEADDR, 1);
Expand All @@ -121,7 +120,7 @@ public function __construct(string $address, mixed $context = null, Options|null
*/
public function listen(): void
{
$this->server->onReadable(function (SocketStream $stream) {
$this->server->onReadable(function (Socket $stream) {
try {
if (!$client = $stream->accept()) {
return;
Expand Down
12 changes: 6 additions & 6 deletions src/Server/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace Ripple\WebSocket\Server;

use Closure;
use Ripple\Socket\SocketStream;
use Ripple\Socket;
use Ripple\Stream\Exception\ConnectionException;
use Ripple\Utils\Output;
use Ripple\WebSocket\Frame\Type;
Expand Down Expand Up @@ -119,24 +119,24 @@ class Connection
private Closure|null $onRequest = null;

/**
* @param SocketStream $stream
* @param Socket $stream
* @param Server $server
*/
public function __construct(public readonly SocketStream $stream, private readonly Server $server)
public function __construct(public readonly Socket $stream, private readonly Server $server)
{
$this->stream->onReadable(fn (SocketStream $stream) => $this->handleRead($stream));
$this->stream->onReadable(fn (Socket $stream) => $this->handleRead($stream));
$this->stream->onClose(fn () => $this->_onClose());
}

/**
* @Author cclilshy
* @Date 2024/8/15 14:44
*
* @param SocketStream $stream
* @param Socket $stream
*
* @return void
*/
private function handleRead(SocketStream $stream): void
private function handleRead(Socket $stream): void
{
try {
$data = $stream->readContinuously(1024);
Expand Down

0 comments on commit 36791c4

Please sign in to comment.