1
0
mirror of https://github.com/danog/ipc.git synced 2024-11-26 20:15:05 +01:00

First stable tag

This commit is contained in:
Daniil Gentili 2020-03-05 21:59:20 +01:00
parent f9d1610c57
commit 70d472f406
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
4 changed files with 11 additions and 10 deletions

View File

@ -1,6 +1,7 @@
# template
[![Build Status](https://img.shields.io/travis/danog/ipc/master.svg?style=flat-square)](https://travis-ci.org/danog/ipc)
[![Build status](https://ci.appveyor.com/api/projects/status/1tcxa257p5dj52ck?svg=true)](https://ci.appveyor.com/project/danog/ipc)
![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
`amphp/ipc` provides an async IPC server.
@ -21,8 +22,8 @@ Server:
require 'vendor/autoload.php';
use Amp\Ipc\IpcServer;
use Amp\Loop;
use Amp\Ipc\Sync\ChannelledSocket;
use Amp\Loop;
use function Amp\asyncCall;
@ -34,17 +35,18 @@ Loop::run(static function () {
echo "Received $payload".PHP_EOL;
if ($payload === 'ping') {
yield $socket->send('pong');
}
}
yield $socket->disconnect();
echo "Closed connection".PHP_EOL;
}
}
echo "Closed connection".PHP_EOL."==========".PHP_EOL;
};
$server = new IpcServer(sys_get_temp_dir().'/test');
$server = new IpcServer(\sys_get_temp_dir().'/test');
while ($socket = yield $server->accept()) {
asyncCall($clientHandler, $socket);
}
});
```
Client:
@ -54,8 +56,8 @@ Client:
require 'vendor/autoload.php';
use Amp\Loop;
use Amp\Ipc\Sync\ChannelledSocket;
use Amp\Loop;
use function Amp\asyncCall;
use function Amp\Ipc\connect;
@ -66,12 +68,11 @@ Loop::run(static function () {
while ($payload = yield $socket->receive()) {
echo "Received $payload".PHP_EOL;
yield $socket->disconnect();
}
echo "Closed connection".PHP_EOL;
};
$channel = yield connect(sys_get_temp_dir().'/test');
$channel = yield connect(\sys_get_temp_dir().'/test');
asyncCall($clientHandler, $channel);
yield $channel->send('ping');
});

View File

@ -14,7 +14,6 @@ Loop::run(static function () {
while ($payload = yield $socket->receive()) {
echo "Received $payload".PHP_EOL;
yield $socket->disconnect();
}
echo "Closed connection".PHP_EOL;
};

View File

@ -16,9 +16,9 @@ Loop::run(static function () {
echo "Received $payload".PHP_EOL;
if ($payload === 'ping') {
yield $socket->send('pong');
}
}
yield $socket->disconnect();
}
}
echo "Closed connection".PHP_EOL."==========".PHP_EOL;
};

View File

@ -58,6 +58,7 @@ final class ChannelledSocket implements Channel
if ($data instanceof ChannelCloseReq) {
yield $this->channel->send(new ChannelCloseAck);
$this->state = self::GOT_FIN_MASK;
yield $this->disconnect();
return null;
}
@ -73,7 +74,7 @@ final class ChannelledSocket implements Channel
public function disconnect(): Promise
{
if (!$this->channel) {
throw new ChannelException('The channel was already closed!');
return new Success();
}
$channel = $this->channel;
$this->channel = null;