/**
  * @inheritDoc
  */
 public function read()
 {
     if (false($this->getSocketPair()->getSocket()->readSelect(2))) {
         return;
     }
     $header = '';
     do {
         $read = $this->getSocketPair()->getSocket()->read(4 - strlen($header));
         if ('' === $read) {
             return null;
         }
         $header .= $read;
     } while (strlen($header) < 4);
     list($len) = array_values(unpack('N', $header));
     // read the full buffer
     $buffer = '';
     do {
         $read = $this->getSocketPair()->getSocket()->read($len - strlen($buffer));
         if ('' === $read) {
             return null;
         }
         $buffer .= $read;
     } while (strlen($buffer) < $len);
     $data = unserialize($buffer);
     return $data;
 }
Esempio n. 2
0
 public function initialize()
 {
     $sockets = [];
     $response = $this->getSocketLib()->createPair($this->getDomain(), $this->getType(), $this->getProtocol(), $sockets);
     if (false($response)) {
         throw new SocketPairException($this->getSocketLib()->stringError($this->getSocketLib()->lastError()));
     }
     $this->left = new Socket();
     $this->left->setSocket(reset($sockets));
     $this->right = new Socket();
     $this->right->setSocket(end($sockets));
 }
Esempio n. 3
0
 public function testTrue()
 {
     $value = true;
     $this->assertFalse(Funct\false($value));
 }
Esempio n. 4
0
/**
 * Checks if needle is not in array
 *
 * @param      $needle
 * @param      $haystack
 * @param null $strict
 *
 * @return bool
 * @author Aurimas Niekis <*****@*****.**>
 */
function not_in_array($needle, $haystack, $strict = null)
{
    return Funct\false(in_array($needle, $haystack, $strict));
}
Esempio n. 5
0
 /**
  * @param int $length
  * @param int $type
  *
  * @return mixed
  * @throws SocketException
  */
 public function read(int $length, int $type = PHP_BINARY_READ)
 {
     $response = $this->getSocketLib()->read($this->getSocket(), $length, $type);
     if (false($response)) {
         throw new SocketException(__METHOD__, $this);
     }
     return $response;
 }