summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-04 12:51:49 +0000
committerGitHub <[email protected]>2020-05-04 12:51:49 +0000
commit670a6de77a0aee53296ac8741853cbec1b416f8d (patch)
treee8f27ec7b1d26c2e2087a37492d68382c5f4cc7b
parentfee8dbb4a6723068050c3396c61180a0733cf988 (diff)
parentbd655985a688c77cb2be96a83b3a26e1ebd983f1 (diff)
Merge #317
317: Add non-optimized relays support r=48d90782 a=vvval resolves #316 Co-authored-by: Valentin V / vvval <[email protected]>
-rw-r--r--src/Worker.php26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/Worker.php b/src/Worker.php
index d9de0fa9..3d1888e3 100644
--- a/src/Worker.php
+++ b/src/Worker.php
@@ -31,12 +31,16 @@ class Worker
/** @var Relay */
private $relay;
+ /** @var bool */
+ private $optimizedRelay;
+
/**
* @param Relay $relay
*/
public function __construct(Relay $relay)
{
$this->relay = $relay;
+ $this->optimizedRelay = method_exists($relay, 'sendPackage');
}
/**
@@ -83,12 +87,22 @@ class Worker
*/
public function send(string $payload = null, string $header = null): void
{
- $this->relay->sendPackage(
- (string)$header,
- Relay::PAYLOAD_CONTROL | ($header === null ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW),
- (string)$payload,
- Relay::PAYLOAD_RAW
- );
+ if (!$this->optimizedRelay) {
+ if ($header === null) {
+ $this->relay->send('', Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE);
+ } else {
+ $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW);
+ }
+
+ $this->relay->send((string)$payload, Relay::PAYLOAD_RAW);
+ } else {
+ $this->relay->sendPackage(
+ (string)$header,
+ Relay::PAYLOAD_CONTROL | ($header === null ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW),
+ (string)$payload,
+ Relay::PAYLOAD_RAW
+ );
+ }
}
/**