Пример #1
0
 function server_loop()
 {
     while (true) {
         $read_fds = $this->fds;
         if (stream_select($read_fds, $write = null, $exp = null, 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($client_socket_id);
                     }
                 } else {
                     $data = sw_fread_stream($socket, $this->buffer_size);
                     if ($data !== false) {
                         $this->protocol->onRecive($socket_id, $data);
                     } else {
                         $this->close($socket_id);
                     }
                 }
             }
         }
     }
 }