Beispiel #1
0
 /**
  * Метод создает новый сокет через socket_create.
  *
  * @return mixed
  * @throws Ext_Io_Net_Socket_Exception
  */
 protected function _createSocket()
 {
     if (is_null($this->_socket)) {
         $socket = socket_create($this->_family->getValue(), $this->_communicationType->getValue(), $this->_connectionString->getProtocolCode());
         if ($socket === false) {
             throw new Ext_Io_Net_Socket_Exception($this->getLastError(), $this->getLastErrorCode());
         }
         $this->_socket = $socket;
         if (is_resource($this->_socket)) {
             socket_set_option($this->_socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $this->_timeout, 'usec' => 0));
         }
     }
     return $this->_socket;
 }
Beispiel #2
0
 /**
  * Метод выполняет создание пары стримов. Часто применяется для межпроцессного взаимодействия.
  *
  * @static
  * @param Ext_Io_Net_Socket_ProtocolFamily    $domain
  * @param Ext_Io_Net_Socket_CommunicationType $type
  * @param Ext_Io_Net_Stream_Protocol          $protocol
  * @return array
  */
 public static function createPair(Ext_Io_Net_Socket_ProtocolFamily $domain, Ext_Io_Net_Socket_CommunicationType $type, Ext_Io_Net_Stream_Protocol $protocol)
 {
     $resources = stream_socket_pair($domain->getValue(), $type->getValue(), $protocol->getValue());
     foreach ($resources as &$resource) {
         $tmpResource = new self();
         $tmpResource->setResource($resource);
         $resource = $tmpResource;
     }
     return $resources;
 }