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')); }
/** * Creates new client instance. * * @param DuplexStreamInterface $connector */ public function __construct(DuplexStreamInterface $connector) { $connector->on('data', function ($data) { $this->read($data); }); $this->connector = $connector; }
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 __construct(Client $client, DuplexStreamInterface $stream) { $this->client = $client; $this->stream = $stream; $that = $this; $this->stream->on('data', function ($data) use($that) { static $buffer; //Handle partial chunks. $buffer .= $data; //If the handler returns true, was successfully processed and can empty buffer if ($that->onStreamData($buffer)) { $buffer = ''; } }); $this->stream->on('close', function () use($client) { $client->setState(Client::STATE_CLOSED); }); }
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]); }); }