Kraken\Stream\AsyncStream::__construct PHP Method

__construct() public method

public __construct ( resource $resource, Kraken\Loop\LoopInterface $loop, boolean $autoClose = true )
$resource resource
$loop Kraken\Loop\LoopInterface
$autoClose boolean
    public function __construct($resource, LoopInterface $loop, $autoClose = true)
    {
        parent::__construct($resource, $autoClose);
        if (function_exists('stream_set_read_buffer')) {
            stream_set_read_buffer($this->resource, 0);
        }
        if (function_exists('stream_set_write_buffer')) {
            stream_set_write_buffer($this->resource, 0);
        }
        $this->loop = $loop;
        $this->listening = false;
        $this->paused = true;
        $this->buffer = new Buffer();
        $this->resume();
    }

Usage Example

Example #1
0
 /**
  * @param string|resource $endpointOrResource
  * @param LoopInterface $loop
  * @param mixed[] $config
  * @throws InstantiationException
  */
 public function __construct($endpointOrResource, LoopInterface $loop, $config = [])
 {
     try {
         if (!is_resource($endpointOrResource)) {
             $endpointOrResource = $this->createClient($endpointOrResource, $config);
         }
         parent::__construct($endpointOrResource, $loop);
     } catch (Error $ex) {
         throw new InstantiationException('SocketClient could not be created.');
     } catch (Exception $ex) {
         throw new InstantiationException('SocketClient could not be created.');
     }
 }