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); } } } } } }
function __construct($host, $port, $timeout = 30) { parent::__construct($host, $port, $timeout = 30); }
/** * @param $protocol * @throws \Exception */ function setProtocol($protocol) { if (self::$useSwooleHttpServer) { $this->protocol = $protocol; } else { parent::setProtocol($protocol); } }