提交 99032b7f 编写于 作者: Y youngwolf

demonstrate strict reference balance between multiple io_context.

上级 5dfdef73
......@@ -165,6 +165,16 @@ protected:
}
#endif
//demonstrate strict reference balance between multiple io_context.
virtual bool change_io_context()
{
if (nullptr == get_matrix())
return false;
reset_next_layer(get_matrix()->get_service_pump().assign_io_context());
return true;
}
private:
void handle_msg(out_msg_ctype& msg)
{
......
......@@ -151,6 +151,9 @@ protected:
virtual bool on_msg_handle(out_msg_type& msg) {return send_msg(std::move(msg));}
#endif
//msg handling end
//demonstrate strict reference balance between multiple io_context.
virtual bool change_io_context() {reset_next_layer(get_server().get_service_pump().assign_io_context()); return true;}
};
class echo_server : public server_base<echo_socket, object_pool<echo_socket>, i_echo_server>
......
......@@ -760,9 +760,9 @@
*
* HIGHLIGHT:
* service_pump support multiple io_context, just needs the number of service thread to be bigger than or equal to the number of io_context.
* Introduce virtual function change_io_context() to ascs::socket to balance the reference of io_context strictly,
* this is because after a socket been reused, its next_layer still based on previous io_context, this may break the balance of io_context,
* re-write this virtual function to re-create the next_layer base on the io_context which has the least references.
* Introduce virtual function change_io_context() to ascs::socket to balance the reference of multiple io_context strictly,
* this is because after a socket been reused, its next_layer still based on previous io_context, this may break the reference balance of
* multiple io_context, re-write this virtual function to re-create the next_layer base on the io_context which has the least references.
* ssl's server_socket_base and client_socket_base already did this, please note.
* Support reliable UDP (based on KCP -- https://github.com/skywind3000/kcp.git).
* Support connected UDP socket, set macro ASCS_UDP_CONNECT_MODE to true to open it, you must also provide peer's ip address via set_peer_addr,
......
......@@ -339,7 +339,7 @@ protected:
virtual void on_close() {unified_out::info_out(ASCS_LLF " on_close()", id());}
virtual void after_close() {} //a good case for using this is to reconnect the server, please refer to client_socket_base.
//reused socket still based on previous io_context, and may break the balance of io_context, if you want to balance io_context strictly,
//reused socket still based on previous io_context, and may break the reference balance of multiple io_context, if you want to balance it strictly,
// re-write this virtual function to re-create the next_layer base on the io_context which has the least references and return true, like:
//virtual bool change_io_context() {this->reset_next_layer(this->get_server().get_service_pump().assign_io_context()); return true;} or
//virtual bool change_io_context()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册