public function __construct(ReadableStream $read, WritableStream $write = null)
{
if (null === $write) {
if (!$read instanceof DuplexStream) {
throw new InvalidArgumentError('Must provide a duplex stream if not providing a write stream.');
}
$this->write = $read;
} else {
$this->write = $write;
}
$this->read = $read;
$this->errorHandler = function ($errno, $errstr) {
throw new ChannelException(sprintf('Received corrupted data. Errno: %d; %s', $errno, $errstr));
};
}