public function __construct($server, DuplexStreamInterface $stdio) { $server->on('connection', function (\React\Socket\Connection $client) use($stdio) { $name = '#' . (int) $client->stream; $log = function ($msg) use($client, &$name, $stdio) { $stdio->write(date('Y-m-d H:i:s') . ' ' . $name . ' ' . $msg . PHP_EOL); }; $log('connected'); $client->on('error', function ($error) use($log) { $msg = $error->getMessage(); while ($error->getPrevious() !== null) { $error = $error->getPrevious(); $msg .= ' - ' . $error->getMessage(); } $log('error: ' . $msg); }); $client->on('target', function ($host, $port) use($log) { $log('tunnel target: ' . $host . ':' . $port); }); $client->on('auth', function ($username) use($log, &$name) { $name .= '(' . $username . ')'; $log('client authenticated'); }); $client->on('ready', function (\React\Stream\Stream $remote) use($log) { $log('tunnel to remote stream #' . (int) $remote->stream . ' successfully established'); }); $client->on('close', function () use($log, &$client) { $dump = ''; $client->emit('dump-close', array(&$dump)); $log('disconnected' . $dump); }); }); }
public function __construct(DuplexStreamInterface $stream, $protocol, $version, $code, $reasonPhrase, $headers) { $this->stream = $stream; $this->protocol = $protocol; $this->version = $version; $this->code = $code; $this->reasonPhrase = $reasonPhrase; $this->headers = $headers; $stream->on('data', array($this, 'handleData')); $stream->on('error', array($this, 'handleError')); $stream->on('end', array($this, 'handleEnd')); }
public function onHeartbeat() { if (isset($this->heartbeat_timer)) { $this->heartbeat_timer->cancel(); } $this->client->getLoop()->addTimer($this->client->getHeartbeatInterval(), function () { //Set a new timeout (2 sec seems reasonable) $this->heartbeat_timer = $this->client->getLoop()->addTimer(2, function () { $this->stream->close(); throw new ConnectionLostException(); }); $this->sendHeartbeat(); }); }
public function __construct(DuplexStreamInterface $stream, Response $response, Request $request) { $this->_stream = $stream; $this->response = $response; $this->request = $request; $stream->on('data', function ($data) { $this->handleData($data); }); $stream->on('end', function (DuplexStreamInterface $stream) { if (is_resource($stream->stream)) { stream_socket_shutdown($stream->stream, STREAM_SHUT_RDWR); stream_set_blocking($stream->stream, false); } }); $stream->on('close', function () { $this->emit('close', [$this]); }); $stream->on('error', function ($error) { $this->emit('error', [$error, $this]); }); }
public function __construct(DuplexStreamInterface $stream, Protocol $protocol = null, PacketSplitter $splitter = null) { if ($protocol === null) { $protocol = Protocol::createFromProbe(0); } if ($splitter === null) { $splitter = new PacketSplitter(new Binary()); } $this->stream = $stream; $this->protocol = $protocol; $this->splitter = $splitter; $stream->on('data', array($this, 'handleData')); $stream->on('end', array($this, 'handleEnd')); $stream->on('error', array($this, 'handleError')); $stream->on('close', array($this, 'handleClose')); $stream->on('drain', array($this, 'handleDrain')); }
public function close() { $this->connector->close(); }