/** * @dataProvider loopProvider */ public function testBufferReadsLargeChunks($condition, $loopFactory) { if (true !== $condition()) { return $this->markTestSkipped('Loop implementation not available'); } $loop = $loopFactory(); list($sockA, $sockB) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0); $streamA = new Stream($sockA, $loop); $streamB = new Stream($sockB, $loop); $bufferSize = 4096; $streamA->bufferSize = $bufferSize; $streamB->bufferSize = $bufferSize; $testString = str_repeat("*", $streamA->bufferSize + 1); $buffer = ""; $streamB->on('data', function ($data, $streamB) use(&$buffer, &$testString) { $buffer .= $data; }); $streamA->write($testString); $loop->tick(); $loop->tick(); $loop->tick(); $streamA->close(); $streamB->close(); $this->assertEquals($testString, $buffer); }
/** * */ public function on() { $client = stream_socket_client('tcp://' . $this->address . ':' . $this->port); $buffer = $this->buffer; $stock = $this->stock; $conn = new Stream($client, $this->loop); $conn->on('data', function ($data) use($conn, $buffer, $stock) { $buffer->setCache($data); if (strspn($buffer->getCache(), 'close')) { $conn->close(); exit; } if (strpos($buffer->getCache(), PHP_EOL) !== false) { echo $data; } $stock->stockize($buffer->getCache()); }); }
/** * Disconnects from a broker. * * @return ExtendedPromiseInterface */ public function disconnect() { if (!$this->isConnected || $this->isDisconnecting) { return new RejectedPromise(new \LogicException('The client is not connected.')); } $this->isDisconnecting = true; $deferred = new Deferred(); $this->startFlow(new OutgoingDisconnectFlow($this->connection), true)->then(function (Connection $connection) use($deferred) { $this->isDisconnecting = false; $this->isConnected = false; $this->emit('disconnect', [$connection, $this]); $deferred->resolve($connection); $this->stream->close(); })->otherwise(function () use($deferred) { $this->isDisconnecting = false; $deferred->reject($this->connection); }); return $deferred->promise(); }
public function close() { return $this->stream->close(); }
/** * @inheritDoc */ public function closeConnection() { $this->reactStream->close(); }
/** * Disconnect the bot from IRC. */ public function disconnect() { $this->write($this->api->getGenerator()->ircQuit()); $this->stream->close(); }
public function close() { $this->pause(); parent::close(); }
/** * @dataProvider loopProvider */ public function testDoesNotWriteDataIfClientSideHasBeenClosed($condition, $loopFactory) { if (true !== $condition()) { return $this->markTestSkipped('Loop implementation not available'); } $loop = $loopFactory(); $server = stream_socket_server('tcp://localhost:0'); $client = stream_socket_client(stream_socket_get_name($server, false)); $peer = stream_socket_accept($server); $streamA = new Stream($peer, $loop); $streamB = new Stream($client, $loop); // end streamA without writing any data $streamA->pause(); $streamA->write('hello'); $streamA->on('close', $this->expectCallableOnce()); $streamB->on('data', $this->expectCallableNever()); $streamB->close(); $loop->run(); $streamA->close(); $streamB->close(); }