Exemplo n.º 1
0
 /**
  * 关闭服务器程序
  * @return unknown_type
  */
 function shutdown()
 {
     //关闭服务器端
     \Swoole\Network\Stream::close($this->server_sock);
     //关闭事件循环
     $this->protocol->onShutdown();
 }
Exemplo n.º 2
0
 function close($client_id)
 {
     Stream::close($this->client_sock[$client_id]);
     $this->client_sock[$client_id] = null;
     $this->fds[$client_id] = null;
     unset($this->client_sock[$client_id], $this->fds[$client_id]);
     $this->protocol->onClose($this, $client_id, 0);
     $this->client_num--;
 }
Exemplo n.º 3
0
 /**
  * 接受连接
  * @return bool|int
  */
 function accept()
 {
     $client_socket = stream_socket_accept($this->server_sock, 0);
     //惊群
     if ($client_socket === false) {
         return false;
     }
     $client_socket_id = (int) $client_socket;
     stream_set_blocking($client_socket, $this->client_block);
     $this->client_sock[$client_socket_id] = $client_socket;
     $this->client_num++;
     if ($this->client_num > $this->max_connect) {
         Network\Stream::close($client_socket);
         return false;
     } else {
         //设置写缓冲区
         stream_set_write_buffer($client_socket, $this->write_buffer_size);
         return $client_socket_id;
     }
 }