Example #1
0
 function server_loop()
 {
     while (true) {
         $read_fds = $this->fds;
         $write = $exp = null;
         if (stream_select($read_fds, $write, $exp, null)) {
             foreach ($read_fds as $socket) {
                 $socket_id = (int) $socket;
                 if ($socket_id == $this->server_socket_id) {
                     if ($client_socket_id = parent::accept()) {
                         $this->fds[$client_socket_id] = $this->client_sock[$client_socket_id];
                         $this->protocol->onConnect($this, $client_socket_id, 0);
                     }
                 } else {
                     $data = Stream::read($socket, $this->buffer_size);
                     if (!empty($data)) {
                         $this->protocol->onReceive($this, $socket_id, 0, $data);
                     } else {
                         $this->close($socket_id);
                     }
                 }
             }
         }
     }
 }
Example #2
0
 function __construct($host, $port, $timeout = 30)
 {
     parent::__construct($host, $port, $timeout = 30);
 }
Example #3
0
 /**
  * @param $protocol
  * @throws \Exception
  */
 function setProtocol($protocol)
 {
     if (self::$useSwooleHttpServer) {
         $this->protocol = $protocol;
     } else {
         parent::setProtocol($protocol);
     }
 }