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:
parent
f9d1610c57
commit
70d472f406
17
README.md
17
README.md
@ -1,6 +1,7 @@
|
|||||||
# template
|
# template
|
||||||
|
|
||||||
[![Build Status](https://img.shields.io/travis/danog/ipc/master.svg?style=flat-square)](https://travis-ci.org/danog/ipc)
|
[![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)
|
![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
|
||||||
|
|
||||||
`amphp/ipc` provides an async IPC server.
|
`amphp/ipc` provides an async IPC server.
|
||||||
@ -21,8 +22,8 @@ Server:
|
|||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
use Amp\Ipc\IpcServer;
|
use Amp\Ipc\IpcServer;
|
||||||
use Amp\Loop;
|
|
||||||
use Amp\Ipc\Sync\ChannelledSocket;
|
use Amp\Ipc\Sync\ChannelledSocket;
|
||||||
|
use Amp\Loop;
|
||||||
|
|
||||||
use function Amp\asyncCall;
|
use function Amp\asyncCall;
|
||||||
|
|
||||||
@ -34,17 +35,18 @@ Loop::run(static function () {
|
|||||||
echo "Received $payload".PHP_EOL;
|
echo "Received $payload".PHP_EOL;
|
||||||
if ($payload === 'ping') {
|
if ($payload === 'ping') {
|
||||||
yield $socket->send('pong');
|
yield $socket->send('pong');
|
||||||
}
|
|
||||||
}
|
|
||||||
yield $socket->disconnect();
|
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()) {
|
while ($socket = yield $server->accept()) {
|
||||||
asyncCall($clientHandler, $socket);
|
asyncCall($clientHandler, $socket);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Client:
|
Client:
|
||||||
@ -54,8 +56,8 @@ Client:
|
|||||||
|
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
use Amp\Loop;
|
|
||||||
use Amp\Ipc\Sync\ChannelledSocket;
|
use Amp\Ipc\Sync\ChannelledSocket;
|
||||||
|
use Amp\Loop;
|
||||||
|
|
||||||
use function Amp\asyncCall;
|
use function Amp\asyncCall;
|
||||||
use function Amp\Ipc\connect;
|
use function Amp\Ipc\connect;
|
||||||
@ -66,12 +68,11 @@ Loop::run(static function () {
|
|||||||
|
|
||||||
while ($payload = yield $socket->receive()) {
|
while ($payload = yield $socket->receive()) {
|
||||||
echo "Received $payload".PHP_EOL;
|
echo "Received $payload".PHP_EOL;
|
||||||
yield $socket->disconnect();
|
|
||||||
}
|
}
|
||||||
echo "Closed connection".PHP_EOL;
|
echo "Closed connection".PHP_EOL;
|
||||||
};
|
};
|
||||||
|
|
||||||
$channel = yield connect(sys_get_temp_dir().'/test');
|
$channel = yield connect(\sys_get_temp_dir().'/test');
|
||||||
asyncCall($clientHandler, $channel);
|
asyncCall($clientHandler, $channel);
|
||||||
yield $channel->send('ping');
|
yield $channel->send('ping');
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,6 @@ Loop::run(static function () {
|
|||||||
|
|
||||||
while ($payload = yield $socket->receive()) {
|
while ($payload = yield $socket->receive()) {
|
||||||
echo "Received $payload".PHP_EOL;
|
echo "Received $payload".PHP_EOL;
|
||||||
yield $socket->disconnect();
|
|
||||||
}
|
}
|
||||||
echo "Closed connection".PHP_EOL;
|
echo "Closed connection".PHP_EOL;
|
||||||
};
|
};
|
||||||
|
@ -16,9 +16,9 @@ Loop::run(static function () {
|
|||||||
echo "Received $payload".PHP_EOL;
|
echo "Received $payload".PHP_EOL;
|
||||||
if ($payload === 'ping') {
|
if ($payload === 'ping') {
|
||||||
yield $socket->send('pong');
|
yield $socket->send('pong');
|
||||||
}
|
|
||||||
}
|
|
||||||
yield $socket->disconnect();
|
yield $socket->disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
echo "Closed connection".PHP_EOL."==========".PHP_EOL;
|
echo "Closed connection".PHP_EOL."==========".PHP_EOL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ final class ChannelledSocket implements Channel
|
|||||||
if ($data instanceof ChannelCloseReq) {
|
if ($data instanceof ChannelCloseReq) {
|
||||||
yield $this->channel->send(new ChannelCloseAck);
|
yield $this->channel->send(new ChannelCloseAck);
|
||||||
$this->state = self::GOT_FIN_MASK;
|
$this->state = self::GOT_FIN_MASK;
|
||||||
|
yield $this->disconnect();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ final class ChannelledSocket implements Channel
|
|||||||
public function disconnect(): Promise
|
public function disconnect(): Promise
|
||||||
{
|
{
|
||||||
if (!$this->channel) {
|
if (!$this->channel) {
|
||||||
throw new ChannelException('The channel was already closed!');
|
return new Success();
|
||||||
}
|
}
|
||||||
$channel = $this->channel;
|
$channel = $this->channel;
|
||||||
$this->channel = null;
|
$this->channel = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user