Skip to content

Commit bdf066d

Browse files
committed
Pre-release: updated copyrighted content
1 parent 329d506 commit bdf066d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2166
-3245
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"php": ">=8.1",
2626
"ext-sockets": "*",
2727
"ext-openssl": "*",
28-
"revolt/event-loop": "^1.0",
29-
"psr/http-message": "*"
28+
"psr/http-message": "*",
29+
"revolt/event-loop": "^1.0"
3030
},
3131
"require-dev": {
3232
"ext-posix": "*",

example/file.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php declare(strict_types=1);
22

3-
use Co\IO;
43
use Ripple\File\Exception\FileException;
4+
use Ripple\File\File;
55

66
include __DIR__ . '/../vendor/autoload.php';
77

88
try {
9-
echo IO::File()->getContents(__FILE__), \PHP_EOL;
9+
echo File::getContents(__FILE__), \PHP_EOL;
1010
} catch (FileException $e) {
1111
echo $e->getMessage(), \PHP_EOL;
1212
exit(1);

example/socket-client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
include __DIR__ . '/../vendor/autoload.php';
44

5-
use Co\IO;
5+
use Ripple\Socket;
66
use Ripple\Stream\Exception\ConnectionException;
77
use Ripple\Utils\Output;
88

99
use function Co\wait;
1010

1111
try {
12-
$connection = IO::Socket()->connect('tcp://127.0.0.1:1080');
12+
$connection = Socket::connect('tcp://127.0.0.1:1080');
1313

1414
# Enable SSL
1515
// $connection->enableSSL();

example/socket-server.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
include __DIR__ . '/../vendor/autoload.php';
44

5-
use Co\IO;
6-
use Ripple\Socket\SocketStream;
5+
use Ripple\Socket;
76

87
use function Co\wait;
98

10-
$onMessage = static function (string $data, SocketStream $stream) {
9+
$onMessage = static function (string $data, Socket $stream) {
1110
$stream->write("Received: $data");
1211
};
1312

14-
$listenClient = static function (SocketStream $stream) use ($onMessage) {
13+
$listenClient = static function (Socket $stream) use ($onMessage) {
1514
$stream->setBlocking(false);
1615
$stream->onReadable(static function () use ($stream, $onMessage) {
1716
$data = $stream->read(1024);
@@ -23,7 +22,7 @@
2322
});
2423
};
2524

26-
$server = IO::Socket()->server('tcp://127.0.0.1:9080');
25+
$server = Socket::server('tcp://127.0.0.1:9080');
2726
$server->setBlocking(false);
2827
$server->setOption(\SOL_SOCKET, \SO_KEEPALIVE, 1);
2928
$server->onReadable(fn () => $listenClient($server->accept()));

example/socket-tunnel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
include __DIR__ . '/../vendor/autoload.php';
44

5-
use Ripple\Socket\Tunnel\Socks5;
65
use Ripple\Stream\Exception\ConnectionException;
6+
use Ripple\Tunnel\Socks5;
77
use Ripple\Utils\Output;
88

99
use function Co\wait;
@@ -15,7 +15,7 @@
1515
'port' => 443
1616
]);
1717

18-
$googleStream = $googleSocks5->getSocketStream();
18+
$googleStream = $googleSocks5->getSocket();
1919
$googleStream->enableSSL();
2020
$googleStream->write("GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n");
2121
$googleStream->onReadable(function () use ($googleStream) {
@@ -42,7 +42,7 @@
4242
]
4343
);
4444

45-
$connection = $google->getSocketStream();
45+
$connection = $google->getSocket();
4646
$connection->enableSSL();
4747
$connection->write("GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n");
4848
$connection->onReadable(function () use ($connection) {

src/Channel.php renamed to src/Channel/Channel.php

Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,24 @@
11
<?php declare(strict_types=1);
2-
/*
3-
* Copyright (c) 2023-2024.
4-
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy
6-
* of this software and associated documentation files (the "Software"), to deal
7-
* in the Software without restriction, including without limitation the rights
8-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
* copies of the Software, and to permit persons to whom the Software is
10-
* furnished to do so, subject to the following conditions:
11-
*
12-
* The above copyright notice and this permission notice shall be included in all
13-
* copies or substantial portions of the Software.
14-
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
* SOFTWARE.
22-
*
23-
* 特此免费授予任何获得本软件及相关文档文件(“软件”)副本的人,不受限制地处理
24-
* 本软件,包括但不限于使用、复制、修改、合并、出版、发行、再许可和/或销售
25-
* 软件副本的权利,并允许向其提供本软件的人做出上述行为,但须符合以下条件:
2+
/**
3+
* Copyright © 2024 cclilshy
4+
* Email: jingnigg@gmail.com
265
*
27-
* 上述版权声明和本许可声明应包含在本软件的所有副本或主要部分中。
6+
* This software is licensed under the MIT License.
7+
* For full license details, please visit: https://opensource.org/licenses/MIT
288
*
29-
* 本软件按“原样”提供,不提供任何形式的保证,无论是明示或暗示的,
30-
* 包括但不限于适销性、特定目的的适用性和非侵权性的保证。在任何情况下,
31-
* 无论是合同诉讼、侵权行为还是其他方面,作者或版权持有人均不对
32-
* 由于软件或软件的使用或其他交易而引起的任何索赔、损害或其他责任承担责任。
9+
* By using this software, you agree to the terms of the license.
10+
* Contributions, suggestions, and feedback are always welcome!
3311
*/
3412

35-
namespace Ripple;
13+
namespace Ripple\Channel;
3614

3715
use Exception;
3816
use Ripple\Channel\Exception\ChannelException;
39-
use Ripple\File\Lock\Lock;
17+
use Ripple\File\Lock;
18+
use Ripple\Kernel;
19+
use Ripple\Stream;
20+
use Ripple\Utils\Path;
4021
use Ripple\Utils\Serialization\Zx7e;
41-
use Ripple\Utils\Utils;
4222
use Throwable;
4323

4424
use function chr;
@@ -88,11 +68,9 @@ class Channel
8868
* @param string $name
8969
* @param bool $owner
9070
*/
91-
public function __construct(
92-
protected readonly string $name,
93-
protected bool $owner = false
94-
) {
95-
$this->path = Utils::tempPath($this->name, 'channel');
71+
public function __construct(protected readonly string $name, protected bool $owner = false)
72+
{
73+
$this->path = Path::temp($this->name, 'channel');
9674
$this->readLock = \Co\lock("{$this->name}.read");
9775
$this->writeLock = \Co\lock("{$this->name}.write");
9876

@@ -120,6 +98,35 @@ public function __construct(
12098
});
12199
}
122100

101+
/**
102+
* @return void
103+
*/
104+
protected function openStream(): void
105+
{
106+
$this->stream = new Stream(fopen($this->path, 'r+'));
107+
$this->stream->setBlocking(false);
108+
$this->zx7e = new Zx7e();
109+
}
110+
111+
/*** @return void */
112+
public function close(): void
113+
{
114+
if ($this->closed) {
115+
return;
116+
}
117+
118+
$this->stream->close();
119+
$this->readLock->close();
120+
$this->writeLock->close();
121+
122+
if ($this->owner) {
123+
file_exists($this->path) && unlink($this->path);
124+
}
125+
126+
$this->closed = true;
127+
cancelForked($this->forkHandlerID);
128+
}
129+
123130
/**
124131
* @param string $name
125132
*
@@ -130,6 +137,16 @@ public static function make(string $name): Channel
130137
return new Channel($name, true);
131138
}
132139

140+
/**
141+
* @param string $name
142+
*
143+
* @return \Ripple\Channel\Channel
144+
*/
145+
public static function open(string $name): Channel
146+
{
147+
return new Channel($name, false);
148+
}
149+
133150
/**
134151
* @param mixed $data
135152
*
@@ -153,16 +170,6 @@ public function send(mixed $data): bool
153170
return true;
154171
}
155172

156-
/**
157-
* @return void
158-
*/
159-
protected function openStream(): void
160-
{
161-
$this->stream = new Stream(fopen($this->path, 'r+'));
162-
$this->stream->setBlocking(false);
163-
$this->zx7e = new Zx7e();
164-
}
165-
166173
/**
167174
* @param bool $blocking
168175
*
@@ -177,8 +184,8 @@ public function receive(bool $blocking = true): mixed
177184
while (1) {
178185
try {
179186
$blocking && $this->stream->waitForReadable();
180-
} catch (Throwable $e) {
181-
throw new ChannelException($e->getMessage());
187+
} catch (Throwable $exception) {
188+
throw new ChannelException($exception->getMessage());
182189
}
183190

184191
if ($this->readLock->lock(blocking: false)) {
@@ -209,8 +216,8 @@ public function receive(bool $blocking = true): mixed
209216
}
210217

211218
return unserialize($data);
212-
} catch (Exception $e) {
213-
throw new ChannelException($e->getMessage());
219+
} catch (Exception $exception) {
220+
throw new ChannelException($exception->getMessage());
214221
} finally {
215222
$this->readLock->unlock();
216223
}
@@ -228,25 +235,6 @@ public function getPath(): string
228235
return $this->path;
229236
}
230237

231-
/*** @return void */
232-
public function close(): void
233-
{
234-
if ($this->closed) {
235-
return;
236-
}
237-
238-
$this->stream->close();
239-
$this->readLock->close();
240-
$this->writeLock->close();
241-
242-
if ($this->owner) {
243-
file_exists($this->path) && unlink($this->path);
244-
}
245-
246-
$this->closed = true;
247-
cancelForked($this->forkHandlerID);
248-
}
249-
250238
public function __destruct()
251239
{
252240
$this->close();

src/Channel/Exception/ChannelException.php

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
11
<?php declare(strict_types=1);
2-
/*
3-
* Copyright (c) 2023-2024.
2+
/**
3+
* Copyright © 2024 cclilshy
4+
* Email: jingnigg@gmail.com
45
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy
6-
* of this software and associated documentation files (the "Software"), to deal
7-
* in the Software without restriction, including without limitation the rights
8-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
* copies of the Software, and to permit persons to whom the Software is
10-
* furnished to do so, subject to the following conditions:
6+
* This software is licensed under the MIT License.
7+
* For full license details, please visit: https://opensource.org/licenses/MIT
118
*
12-
* The above copyright notice and this permission notice shall be included in all
13-
* copies or substantial portions of the Software.
14-
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
* SOFTWARE.
22-
*
23-
* 特此免费授予任何获得本软件及相关文档文件(“软件”)副本的人,不受限制地处理
24-
* 本软件,包括但不限于使用、复制、修改、合并、出版、发行、再许可和/或销售
25-
* 软件副本的权利,并允许向其提供本软件的人做出上述行为,但须符合以下条件:
26-
*
27-
* 上述版权声明和本许可声明应包含在本软件的所有副本或主要部分中。
28-
*
29-
* 本软件按“原样”提供,不提供任何形式的保证,无论是明示或暗示的,
30-
* 包括但不限于适销性、特定目的的适用性和非侵权性的保证。在任何情况下,
31-
* 无论是合同诉讼、侵权行为还是其他方面,作者或版权持有人均不对
32-
* 由于软件或软件的使用或其他交易而引起的任何索赔、损害或其他责任承担责任。
9+
* By using this software, you agree to the terms of the license.
10+
* Contributions, suggestions, and feedback are always welcome!
3311
*/
3412

3513
namespace Ripple\Channel\Exception;

src/Channel/README.md

Whitespace-only changes.

0 commit comments

Comments
 (0)