//we don't have fixed_length_packer, so use packer instead, but need to pack msgs with native manner.
...
...
@@ -184,7 +184,7 @@ int main(int argc, const char* argv[])
//send \0 character too, because asio_client used inflexible_buffer as its msg type, it will not append \0 character automatically as std::string does,
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_tcp_socket's send buffer
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_tcp_socket's send buffer successfully
//if can_overflow equal to false and the buffer is not available, will wait until it becomes available
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_udp_socket's send buffer
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_udp_socket's send buffer successfully
//if can_overflow equal to false and the buffer is not available, will wait until it becomes available
//st_socket will invoke dispatch_msg() when got some msgs. if these msgs can't push into recv_msg_buffer cause of receive buffer overflow,
//st_socket will delay 50 milliseconds(non-blocking) to invoke dispatch_msg() again, and now, as you known, temp_msg_buffer is used to hold these msgs temporarily.
size_tcurrent_msg_length()const{returnraw_buff.size();}//current msg's total length(not include the head), 0 means don't know
public:
...
...
@@ -279,12 +294,11 @@ public:
private:
HEAD_TYPEhead_buff;
//please notice that we don't have a fixed size array with maximum size any more(like the default unpacker).
//please note that we don't have a fixed size array with maximum size any more(like the default unpacker).
//this is very useful if you have very few but very large msgs, fox example:
//you have a very large msg(1M size), but all others are very small, if you use a fixed size array to hold msgs in the unpackers,
//all the unpackers must have an array with at least 1M size, each st_socket will have a unpacker, this will cause your application occupy very large memory but with
//very low utilization ratio.
//this inflexible_unpacker will resolve the above problem, and with another benefit: no memory copying needed any more.
//all the unpackers must have an array with at least 1M size, each st_socket will have a unpacker, this will cause your application occupy very large memory but with very low utilization ratio.
//this unbuffered_unpacker will resolve above problem, and with another benefit: no memory replication needed any more.
msg_typeraw_buff;
intstep;//-1-error format, 0-want the head, 1-want the body
// for (BOOST_AUTO(iter, object_can.begin()); n-- > 0 && iter != object_can.end(); ++iter)
// (*iter)->graceful_close();
//notice: this method need to define AUTO_CLEAR_CLOSED_SOCKET and CLEAR_CLOSED_SOCKET_INTERVAL macro, because it just closed the st_socket,
//not really removed them from object pool, this will cause test_client still send data to them, and wait responses from them.
//not really removed them from object pool, this will cause test_client still send data via them, and wait responses from them.
//for this scenario, the smaller CLEAR_CLOSED_SOCKET_INTERVAL is, the better experience you will get, so set it to 1 second.
//method #2
while(n-->0)
graceful_close(at(0));
//notice: this method directly remove the client from object pool (and insert into list temp_object_can), and close the st_socket.
//clients in list temp_object_can will be reused if new clients needed (REUSE_OBJECT macro been defined), or be truly freed from memory
//CLOSED_SOCKET_MAX_DURATION seconds later (but check interval is SOCKET_FREE_INTERVAL seconds, so the maximum delay is CLOSED_SOCKET_MAX_DURATION + SOCKET_FREE_INTERVAL).
//this is a equivalence of calling i_server::del_client in st_server_socket_base::on_recv_error (see st_server_socket_base for more details).
//notice: this method directly remove clients from object pool, and close them, not require AUTO_CLEAR_CLOSED_SOCKET and CLEAR_CLOSED_SOCKET_INTERVAL macro
//this is a equivalence of calling i_server::del_client in st_server_socket_base::on_recv_error(see st_server_socket_base for more details).
//guarantee send msg successfully even if can_overflow equal to false
//success at here just means put the msg into st_tcp_socket's send buffer
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_tcp_socket's send buffer successfully
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_tcp_socket's send buffer
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_tcp_socket's send buffer successfully
//if can_overflow equal to false and the buffer is not available, will wait until it becomes available
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_udp_socket's send buffer
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_udp_socket's send buffer successfully
//if can_overflow equal to false and the buffer is not available, will wait until it becomes available
//st_socket will invoke dispatch_msg() when got some msgs. if these msgs can't push into recv_msg_buffer cause of receive buffer overflow,
//st_socket will delay 50 milliseconds(non-blocking) to invoke dispatch_msg() again, and now, as you known, temp_msg_buffer is used to hold these msgs temporarily.
size_tcurrent_msg_length()const{returnraw_buff.size();}//current msg's total length(not include the head), 0 means don't know
public:
...
...
@@ -277,12 +293,11 @@ public:
private:
HEAD_TYPEhead_buff;
//please notice that we don't have a fixed size array with maximum size any more(like the default unpacker).
//please note that we don't have a fixed size array with maximum size any more(like the default unpacker).
//this is very useful if you have very few but very large msgs, fox example:
//you have a very large msg(1M size), but all others are very small, if you use a fixed size array to hold msgs in the unpackers,
//all the unpackers must have an array with at least 1M size, each st_socket will have a unpacker, this will cause your application occupy very large memory but with
//very low utilization ratio.
//this inflexible_unpacker will resolve the above problem, and with another benefit: no memory copying needed any more.
//all the unpackers must have an array with at least 1M size, each st_socket will have a unpacker, this will cause your application occupy very large memory but with very low utilization ratio.
//this unbuffered_unpacker will resolve above problem, and with another benefit: no memory replication needed any more.
msg_typeraw_buff;
intstep;//-1-error format, 0-want the head, 1-want the body
//notice: this method need to define AUTO_CLEAR_CLOSED_SOCKET and CLEAR_CLOSED_SOCKET_INTERVAL macro, because it just closed the st_socket,
//not really removed them from object pool, this will cause test_client still send data to them, and wait responses from them.
//not really removed them from object pool, this will cause test_client still send data via them, and wait responses from them.
//for this scenario, the smaller CLEAR_CLOSED_SOCKET_INTERVAL is, the better experience you will get, so set it to 1 second.
//method #2
while(n-->0)
graceful_close(at(0));
//notice: this method directly remove the client from object pool (and insert into list temp_object_can), and close the st_socket.
//clients in list temp_object_can will be reused if new clients needed (REUSE_OBJECT macro been defined), or be truly freed from memory
//CLOSED_SOCKET_MAX_DURATION seconds later (but check interval is SOCKET_FREE_INTERVAL seconds, so the maximum delay is CLOSED_SOCKET_MAX_DURATION + SOCKET_FREE_INTERVAL).
//this is a equivalence of calling i_server::del_client in st_server_socket_base::on_recv_error (see st_server_socket_base for more details).
//notice: this method directly remove clients from object pool, and close them, not require AUTO_CLEAR_CLOSED_SOCKET and CLEAR_CLOSED_SOCKET_INTERVAL macro
//this is a equivalence of calling i_server::del_client in st_server_socket_base::on_recv_error(see st_server_socket_base for more details).
//guarantee send msg successfully even if can_overflow equal to false
//success at here just means put the msg into st_tcp_socket's send buffer
//guarantee send msg successfully even if can_overflow equal to false, success at here just means putting the msg into st_tcp_socket's send buffer successfully