예제 #1
0
 /**
  * 关闭服务器程序
  * @return unknown_type
  */
 function shutdown()
 {
     //关闭服务器端
     sw_socket_close($this->server_sock);
     //关闭事件循环
     $this->protocol->onShutdown($this);
 }
예제 #2
0
 function close($client_id)
 {
     sw_socket_close($this->client_sock[$client_id]);
     $this->client_sock[$client_id] = null;
     unset($this->client_sock[$client_id]);
     $this->protocol->onClose($client_id);
 }
예제 #3
0
 /**
  * 关闭服务器程序
  * @return unknown_type
  */
 function shutdown()
 {
     //关闭服务器端
     sw_socket_close($this->server_sock, $this->server_event);
     //关闭事件循环
     event_base_loopexit($this->base_event);
     $this->protocol->onShutdown();
 }
예제 #4
0
 function accept()
 {
     $client_socket = stream_socket_accept($this->server_sock);
     $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) {
         sw_socket_close($client_socket);
         return false;
     } else {
         //设置写缓冲区
         stream_set_write_buffer($client_socket, $this->write_buffer_size);
         return $client_socket_id;
     }
 }
예제 #5
0
 /**
  * 关闭某个客户端
  * @return unknown_type
  */
 function close($client_id)
 {
     sw_socket_close($this->client_sock[$client_id], $this->client_event[$client_id]);
     unset($this->client_sock[$client_id], $this->client_event[$client_id]);
     $this->protocol->onClose($client_id);
     $this->client_num--;
 }