Beispiel #1
0
 public function testClosedCreation()
 {
     $stream = new MioStream(fsockopen('127.0.0.1', 8888, $errno = null, $errstr = null), '127.0.0.1:8888');
     $stream->close();
     try {
         $key = new MioSelectionKey($stream, 0);
         $this->fail();
     } catch (MioClosedException $e) {
         $this->pass();
     }
 }
Beispiel #2
0
 /**
  * Creates a valid selection key or throws an exception. An 
  * exception will be thrown if the stream is blocking or closed; 
  * the interest ops are invalid or the attachment is present
  * and not an object.
  *
  * @param MioStream $stream
  * @param int $interest_ops
  * @param Object $attachment
  * @throws MioException
  */
 public function __construct($stream, $interest_ops, $attachment = null)
 {
     if ($stream->isBlocking()) {
         throw new MioBlockingException("Stream must be in non-blocking mode to be registered");
     }
     if (!$stream->isOpen()) {
         throw new MioClosedException("Stream must be open to be registered");
     }
     $this->stream = $stream;
     $this->setInterestOps($interest_ops);
     $this->attach($attachment);
 }
Beispiel #3
0
 public function testAccept()
 {
     $stream = new MioStream($this->server, '127.0.0.1:8888');
     $this->assertTrue($stream->accept() instanceof MioStream);
 }
Beispiel #4
0
 /**
  * Get the key associating this selector with a given stream
  *
  * @param MioStream $stream
  * @return MioSelectionKey
  */
 public function keyFor($stream)
 {
     $s = $stream->getStream();
     if (isset($this->key_lookup[$s])) {
         return $this->key_lookup[$s];
     }
 }