diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:23:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:23:16 +0000 |
commit | 3e97c51418e6d27e9a81906f347fcb7c78e27d4f (patch) | |
tree | ee596ce1bc9840661386f96f9b8d1f919a106317 /vendor/gipfl/protocol | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-incubator-3e97c51418e6d27e9a81906f347fcb7c78e27d4f.tar.xz icingaweb2-module-incubator-3e97c51418e6d27e9a81906f347fcb7c78e27d4f.zip |
Adding upstream version 0.20.0.upstream/0.20.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gipfl/protocol')
-rw-r--r-- | vendor/gipfl/protocol/LICENSE | 21 | ||||
-rw-r--r-- | vendor/gipfl/protocol/composer.json | 26 | ||||
-rw-r--r-- | vendor/gipfl/protocol/src/Exception/ProtocolError.php | 9 | ||||
-rw-r--r-- | vendor/gipfl/protocol/src/Generic/AbstractStreamWrapper.php | 139 |
4 files changed, 195 insertions, 0 deletions
diff --git a/vendor/gipfl/protocol/LICENSE b/vendor/gipfl/protocol/LICENSE new file mode 100644 index 0000000..dd88e09 --- /dev/null +++ b/vendor/gipfl/protocol/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2018 Thomas Gelf + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/gipfl/protocol/composer.json b/vendor/gipfl/protocol/composer.json new file mode 100644 index 0000000..4c204f3 --- /dev/null +++ b/vendor/gipfl/protocol/composer.json @@ -0,0 +1,26 @@ +{ + "name": "gipfl/protocol", + "description": "Base library for some network protocol implementations", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Thomas Gelf", + "email": "thomas@gelf.net" + } + ], + "config": { + "sort-packages": true + }, + "autoload": { + "psr-4": { + "gipfl\\Protocol\\Exception\\": "src/Exception", + "gipfl\\Protocol\\Generic\\": "src/Generic" + } + }, + "require": { + "php": ">=5.4.0", + "evenement/evenement": "^2", + "react/stream": "^1.0" + } +} diff --git a/vendor/gipfl/protocol/src/Exception/ProtocolError.php b/vendor/gipfl/protocol/src/Exception/ProtocolError.php new file mode 100644 index 0000000..b4a42ca --- /dev/null +++ b/vendor/gipfl/protocol/src/Exception/ProtocolError.php @@ -0,0 +1,9 @@ +<?php + +namespace gipfl\Protocol\Exception; + +use Exception; + +class ProtocolError extends Exception +{ +} diff --git a/vendor/gipfl/protocol/src/Generic/AbstractStreamWrapper.php b/vendor/gipfl/protocol/src/Generic/AbstractStreamWrapper.php new file mode 100644 index 0000000..12f6e82 --- /dev/null +++ b/vendor/gipfl/protocol/src/Generic/AbstractStreamWrapper.php @@ -0,0 +1,139 @@ +<?php + +namespace gipfl\Protocol\Generic; + +use Evenement\EventEmitterTrait; +use Exception; +use React\Stream\DuplexStreamInterface; +use React\Stream\ReadableStreamInterface; +use React\Stream\Util; +use React\Stream\WritableStreamInterface; +use RuntimeException; + +abstract class AbstractStreamWrapper implements DuplexStreamInterface +{ + use EventEmitterTrait; + + /** @var ReadableStreamInterface */ + protected $input; + + /** @var WritableStreamInterface */ + protected $output; + + private $closed = false; + + public function __construct(ReadableStreamInterface $in, WritableStreamInterface $out = null) + { + $this->readFrom($in); + if ($out === null && $in instanceof WritableStreamInterface) { + $this->writeTo($in); + } else { + $this->writeTo($out); + } + } + + abstract public function handleData($data); + + protected function readFrom(ReadableStreamInterface $input) + { + $this->input = $input; + if (! $input->isReadable()) { + $this->close(); + return; + } + $input->on('data', function ($data) { + $this->handleData($data); + }); + $input->on('end', function () { + $this->handleEnd(); + }); + $input->on('close', function () { + $this->close(); + }); + $input->on('error', function (Exception $error) { + $this->handleError($error); + }); + } + + protected function writeTo(WritableStreamInterface $output) + { + $this->output = $output; + if (! $this->output->isWritable()) { + $this->close(); + throw new RuntimeException('Cannot write to output'); + } + + $output->on('drain', function () { + $this->handleDrain(); + }); + $output->on('close', function () { + $this->close(); + }); + $output->on('error', function (Exception $error) { + $this->handleError($error); + }); + } + + protected function handleDrain() + { + $this->emit('drain'); + } + + protected function handleEnd() + { + if (! $this->closed) { + $this->emit('end'); + $this->close(); + } + } + + public function isReadable() + { + return !$this->closed && $this->input->isReadable(); + } + + public function isWritable() + { + return !$this->closed && $this->output->isWritable(); + } + + public function close() + { + if ($this->closed) { + return; + } + + $this->closed = true; + $this->input->close(); + $this->output->close(); + + $this->emit('close'); + $this->removeAllListeners(); + } + + public function pause() + { + $this->input->pause(); + } + + public function resume() + { + $this->input->resume(); + } + + public function pipe(WritableStreamInterface $dest, array $options = []) + { + Util::pipe($this, $dest, $options); + + return $dest; + } + + /** + * @param Exception $error + */ + protected function handleError(Exception $error) + { + $this->emit('error', [$error]); + $this->close(); + } +} |