Exemplo n.º 1
0
 /**
  * @param resource $socket
  * @param bool $autoClose True to close the resource on destruct, false to leave it open.
  */
 public function __construct($socket, bool $autoClose = true)
 {
     parent::__construct($socket, $autoClose);
     $this->queue = new \SplQueue();
     $this->poll = $this->createPoll($socket, $this->queue);
     $this->onCancelled = function () {
         $this->poll->cancel();
         $this->queue->shift();
     };
     try {
         list($this->address, $this->port) = Socket\getName($socket, false);
     } catch (FailureException $exception) {
         $this->close();
     }
 }
Exemplo n.º 2
0
 /**
  * @param resource $socket
  * @param bool $autoClose True to close the resource on destruct, false to leave it open.
  */
 public function __construct($socket, bool $autoClose = true)
 {
     parent::__construct($socket, $autoClose);
     stream_set_read_buffer($socket, 0);
     stream_set_write_buffer($socket, 0);
     stream_set_chunk_size($socket, self::MAX_PACKET_SIZE);
     $this->readQueue = new \SplQueue();
     $this->writeQueue = new \SplQueue();
     $this->poll = $this->createPoll($socket, $this->readQueue);
     $this->await = $this->createAwait($socket, $this->writeQueue);
     $this->onReceiveCancelled = function () {
         $this->poll->cancel();
         $this->readQueue->shift();
     };
     $this->onSendCancelled = function (\Exception $exception) {
         $this->free($exception);
     };
     try {
         list($this->address, $this->port) = Socket\getName($socket, false);
     } catch (FailureException $exception) {
         $this->close();
     }
 }