mirror of
https://github.com/danog/ipc.git
synced 2024-11-26 20:15:05 +01:00
Add missing files
This commit is contained in:
parent
787ca479ef
commit
1a30e5492a
@ -21,11 +21,11 @@ Server:
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Amp\Ipc\IpcServer;
|
||||
use Amp\Ipc\Sync\ChannelledSocket;
|
||||
use Amp\Loop;
|
||||
|
||||
use function Amp\asyncCall;
|
||||
use function Amp\Ipc\listen;
|
||||
|
||||
Loop::run(static function () {
|
||||
$clientHandler = function (ChannelledSocket $socket) {
|
||||
@ -41,7 +41,7 @@ Loop::run(static function () {
|
||||
echo "Closed connection".PHP_EOL."==========".PHP_EOL;
|
||||
};
|
||||
|
||||
$server = new IpcServer(\sys_get_temp_dir().'/test');
|
||||
$server = listen(\sys_get_temp_dir().'/test');
|
||||
while ($socket = yield $server->accept()) {
|
||||
asyncCall($clientHandler, $socket);
|
||||
}
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Amp\Ipc\IpcServer;
|
||||
use Amp\Ipc\Sync\ChannelledSocket;
|
||||
use Amp\Loop;
|
||||
|
||||
use function Amp\asyncCall;
|
||||
use function Amp\Ipc\listen;
|
||||
|
||||
Loop::run(static function () {
|
||||
$clientHandler = function (ChannelledSocket $socket) {
|
||||
@ -22,7 +22,7 @@ Loop::run(static function () {
|
||||
echo "Closed connection".PHP_EOL."==========".PHP_EOL;
|
||||
};
|
||||
|
||||
$server = new IpcServer(\sys_get_temp_dir().'/test');
|
||||
$server = listen(\sys_get_temp_dir().'/test');
|
||||
while ($socket = yield $server->accept()) {
|
||||
asyncCall($clientHandler, $socket);
|
||||
}
|
||||
|
@ -7,6 +7,17 @@ use Amp\Promise;
|
||||
|
||||
use function Amp\call;
|
||||
|
||||
/**
|
||||
* Create IPC server.
|
||||
*
|
||||
* @param string $uri Local endpoint on which to listen for requests
|
||||
*
|
||||
* @return IpcServer
|
||||
*/
|
||||
function listen(string $uri): IpcServer
|
||||
{
|
||||
return new IpcServer($uri);
|
||||
}
|
||||
/**
|
||||
* Connect to IPC server.
|
||||
*
|
||||
|
30
test/Fixtures/echoServer.php
Normal file
30
test/Fixtures/echoServer.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
\error_reporting(E_ALL);
|
||||
\ini_set('log_errors', 1);
|
||||
\ini_set('error_log', '/tmp/amphp.log');
|
||||
\error_log('Inited IPC test!');
|
||||
|
||||
use Amp\Ipc\IpcServer;
|
||||
use Amp\Ipc\Sync\ChannelledSocket;
|
||||
use Amp\Parallel\Sync\Channel;
|
||||
|
||||
use function Amp\delay;
|
||||
|
||||
return function (Channel $channel) use ($argv) {
|
||||
$server = new IpcServer($argv[1], $argv[2] === "1" ? true : false);
|
||||
|
||||
yield $channel->send($server->getUri());
|
||||
|
||||
$socket = yield $server->accept();
|
||||
|
||||
if (!$socket instanceof ChannelledSocket) {
|
||||
throw new \RuntimeException('Socket is not instance of ChanneledSocket');
|
||||
}
|
||||
|
||||
while (yield $socket->receive());
|
||||
yield $socket->disconnect();
|
||||
|
||||
$server->close();
|
||||
|
||||
return $server->accept();
|
||||
};
|
Loading…
Reference in New Issue
Block a user