diff --git a/examples/echo_client/echo_client.cpp b/examples/echo_client/echo_client.cpp index 8a888723f3a9e02ce401157ff906cd6ae01bf821..d32313b63e31ede8d8068fcb8456a5377425d0ac 100644 --- a/examples/echo_client/echo_client.cpp +++ b/examples/echo_client/echo_client.cpp @@ -21,17 +21,17 @@ //use the following macro to control the type of packer and unpacker #define PACKER_UNPACKER_TYPE 0 //0-default packer and unpacker, head(length) + body -//1-replaceable packer and unpacker, head(length) + body +//1-packer2 and unpacker2, head(length) + body //2-fixed length packer and unpacker //3-prefix and/or suffix packer and unpacker #if 1 == PACKER_UNPACKER_TYPE #if defined(_MSC_VER) && _MSC_VER <= 1800 -#define ASCS_DEFAULT_PACKER replaceable_packer> +#define ASCS_DEFAULT_PACKER packer2> #else -#define ASCS_DEFAULT_PACKER replaceable_packer<> +#define ASCS_DEFAULT_PACKER packer2<> #endif -#define ASCS_DEFAULT_UNPACKER replaceable_unpacker<> +#define ASCS_DEFAULT_UNPACKER unpacker2<> #elif 2 == PACKER_UNPACKER_TYPE #undef ASCS_HEARTBEAT_INTERVAL #define ASCS_HEARTBEAT_INTERVAL 0 //not support heartbeat diff --git a/examples/echo_server/echo_server.cpp b/examples/echo_server/echo_server.cpp index 8826de0d5a4e29e3dcda246db143f098a9915b1f..bda309ecf5b580c80c36ae5989fdf4acb3b71d9b 100644 --- a/examples/echo_server/echo_server.cpp +++ b/examples/echo_server/echo_server.cpp @@ -22,17 +22,17 @@ //use the following macro to control the type of packer and unpacker #define PACKER_UNPACKER_TYPE 0 //0-default packer and unpacker, head(length) + body -//1-replaceable packer and unpacker, head(length) + body +//1-packer2 and unpacker2, head(length) + body //2-fixed length packer and unpacker //3-prefix and/or suffix packer and unpacker #if 1 == PACKER_UNPACKER_TYPE #if defined(_MSC_VER) && _MSC_VER <= 1800 -#define ASCS_DEFAULT_PACKER replaceable_packer> +#define ASCS_DEFAULT_PACKER packer2> #else -#define ASCS_DEFAULT_PACKER replaceable_packer<> +#define ASCS_DEFAULT_PACKER packer2<> #endif -#define ASCS_DEFAULT_UNPACKER replaceable_unpacker<> +#define ASCS_DEFAULT_UNPACKER unpacker2<> #elif 2 == PACKER_UNPACKER_TYPE #undef ASCS_HEARTBEAT_INTERVAL #define ASCS_HEARTBEAT_INTERVAL 0 //not support heartbeat diff --git a/examples/file_client/file_client.cpp b/examples/file_client/file_client.cpp index 4670ceac73dbe5e0e0b4a12426ddbe1ffbc186ec..0b5f5c8cb88f63e7632bbaf3f88d83cfdac02826 100644 --- a/examples/file_client/file_client.cpp +++ b/examples/file_client/file_client.cpp @@ -7,7 +7,7 @@ #define ASCS_PASSIVE_RECV //#define ASCS_INPUT_QUEUE non_lock_queue //we cannot use non_lock_queue, because we also send messages (talking messages) out of ascs::socket::on_msg_send(). -#define ASCS_DEFAULT_UNPACKER replaceable_unpacker<> +#define ASCS_DEFAULT_UNPACKER unpacker2<> #define ASCS_RECV_BUFFER_TYPE std::vector //scatter-gather buffer, it's very useful under certain situations (for example, ring buffer). #define ASCS_SCATTERED_RECV_BUFFER //used by unpackers, not belongs to ascs //configuration diff --git a/examples/file_client/unpacker.h b/examples/file_client/unpacker.h index 4a73dde3831c042f833855af2edb62108643a586..133c71dca524662fdf75ec867ebed23e383ba994 100644 --- a/examples/file_client/unpacker.h +++ b/examples/file_client/unpacker.h @@ -9,7 +9,7 @@ using namespace ascs::tcp; extern std::atomic_int_fast64_t received_size; -class data_unpacker : public i_unpacker +class data_unpacker : public i_unpacker> { public: data_unpacker(FILE* file, fl_type data_len) : _file(file), _data_len(data_len) diff --git a/examples/file_server/file_server.cpp b/examples/file_server/file_server.cpp index 4092e49685100e5ed204e2f1bccab1b60b5f0792..51e9c128ae4526987d8309ee418ebe2be3ba6e67 100644 --- a/examples/file_server/file_server.cpp +++ b/examples/file_server/file_server.cpp @@ -12,9 +12,9 @@ //sent to file_client, so sending buffer will always be empty, which means we will never operate sending buffer concurrently, //so need no locks. #if defined(_MSC_VER) && _MSC_VER <= 1800 -#define ASCS_DEFAULT_PACKER replaceable_packer> +#define ASCS_DEFAULT_PACKER packer2> #else -#define ASCS_DEFAULT_PACKER replaceable_packer<> +#define ASCS_DEFAULT_PACKER packer2<> #endif #define ASCS_RECV_BUFFER_TYPE std::vector //scatter-gather buffer, it's very useful under certain situations (for example, ring buffer). #define ASCS_SCATTERED_RECV_BUFFER //used by unpackers, not belongs to ascs diff --git a/examples/file_server/file_socket.cpp b/examples/file_server/file_socket.cpp index 0ce101739bc5059c1feab206438f50a21afbff83..279536dc36f2ff13195167fa790381b0860d8a18 100644 --- a/examples/file_server/file_socket.cpp +++ b/examples/file_server/file_socket.cpp @@ -10,9 +10,9 @@ //sent to file_client, so sending buffer will always be empty, which means we will never operate sending buffer concurrently, //so need no locks. #if defined(_MSC_VER) && _MSC_VER <= 1800 -#define ASCS_DEFAULT_PACKER replaceable_packer> +#define ASCS_DEFAULT_PACKER packer2> #else -#define ASCS_DEFAULT_PACKER replaceable_packer<> +#define ASCS_DEFAULT_PACKER packer2<> #endif #define ASCS_RECV_BUFFER_TYPE std::vector //scatter-gather buffer, it's very useful under certain situations (for example, ring buffer). #define ASCS_SCATTERED_RECV_BUFFER //used by unpackers, not belongs to ascs diff --git a/examples/socket_management/server.h b/examples/socket_management/server.h index 81e5f3d241cef8459775b3355ae37956661e9146..1e8e3faefd3d6416c4c3be586f949dca6aa63bd6 100644 --- a/examples/socket_management/server.h +++ b/examples/socket_management/server.h @@ -15,7 +15,7 @@ public: protected: //msg handling #if 1 == PACKER_UNPACKER_TYPE - //replaceable_unpacker uses auto_buffer or shared_buffer as its message type + //unpacker2 uses auto_buffer or shared_buffer as its message type virtual bool on_msg_handle(out_msg_type& msg) { auto raw_msg = new string_buffer(); diff --git a/examples/socket_management/socket_management.cpp b/examples/socket_management/socket_management.cpp index a952e26dbb6715fbf84d15e5c2779f7668f5b94b..63d10269dc6e5b67280829b3e67fc76f8d8bc7a9 100644 --- a/examples/socket_management/socket_management.cpp +++ b/examples/socket_management/socket_management.cpp @@ -12,17 +12,17 @@ //use the following macro to control the type of packer and unpacker #define PACKER_UNPACKER_TYPE 0 //0-default packer and unpacker, head(length) + body -//1-replaceable packer and unpacker, head(length) + body +//1-packer2 and unpacker2, head(length) + body //2-fixed length packer and unpacker //3-prefix and/or suffix packer and unpacker #if 1 == PACKER_UNPACKER_TYPE #if defined(_MSC_VER) && _MSC_VER <= 1800 -#define ASCS_DEFAULT_PACKER replaceable_packer> +#define ASCS_DEFAULT_PACKER packer2> #else -#define ASCS_DEFAULT_PACKER replaceable_packer<> +#define ASCS_DEFAULT_PACKER packer2<> #endif -#define ASCS_DEFAULT_UNPACKER replaceable_unpacker<> +#define ASCS_DEFAULT_UNPACKER unpacker2<> #elif 2 == PACKER_UNPACKER_TYPE #undef ASCS_HEARTBEAT_INTERVAL #define ASCS_HEARTBEAT_INTERVAL 0 //not support heartbeat diff --git a/examples/ssl_test/ssl_test.cpp b/examples/ssl_test/ssl_test.cpp index 64be7680c88e34c3890789a25a8df39db5615677..11abd2d16556b941bada8156ab0a5c22afafc01b 100644 --- a/examples/ssl_test/ssl_test.cpp +++ b/examples/ssl_test/ssl_test.cpp @@ -7,11 +7,11 @@ #define ASCS_REUSE_SSL_STREAM #define ASCS_ENHANCED_STABILITY //#if defined(_MSC_VER) && _MSC_VER <= 1800 -//#define ASCS_DEFAULT_PACKER replaceable_packer> +//#define ASCS_DEFAULT_PACKER packer2> //#else -//#define ASCS_DEFAULT_PACKER replaceable_packer<> +//#define ASCS_DEFAULT_PACKER packer2<> //#endif -//#define ASCS_DEFAULT_UNPACKER replaceable_unpacker<> +//#define ASCS_DEFAULT_UNPACKER unpacker2<> #define ASCS_HEARTBEAT_INTERVAL 5 //SSL has supported heartbeat because we used user data instead of OOB to implement //heartbeat since 1.2.0 //configuration diff --git a/examples/udp_test/udp_test.cpp b/examples/udp_test/udp_test.cpp index a4851e03db219537e77bd7547270dc3c88be8c7b..0fcbb2200f05ae02666e3286d5ea22e3636678f9 100644 --- a/examples/udp_test/udp_test.cpp +++ b/examples/udp_test/udp_test.cpp @@ -11,9 +11,8 @@ //some messages will be dispatched via on_msg_handle(), some messages will be returned via sync_recv_msg(), //type more than one messages (separate them by space) in one line with ENTER key to send them, //you will see them cross together on the receiver's screen. -//#define ASCS_DEFAULT_UDP_UNPACKER replaceable_udp_unpacker<> -#define ASCS_HEARTBEAT_INTERVAL 5 //neither udp_unpacker nor replaceable_udp_unpacker support heartbeat message, - //so heartbeat will be treated as normal message. +//#define ASCS_DEFAULT_UDP_UNPACKER udp_unpacker2<> +#define ASCS_HEARTBEAT_INTERVAL 5 //neither udp_unpacker nor udp_unpacker2 support heartbeat message, so heartbeat will be treated as normal message. //configuration #include diff --git a/include/ascs/base.h b/include/ascs/base.h index b71f0a19ba7cc1102f5961c3e4f82c6f33b5a9c8..2c400371ef85f0bbce2af89de99c923aeb25f6d1 100644 --- a/include/ascs/base.h +++ b/include/ascs/base.h @@ -125,10 +125,10 @@ public: protected: buffer_type buffer; }; -typedef auto_buffer replaceable_buffer; //convert '->' operation to '.' operation //user need to allocate object, and shared_buffer will free it +//not like auto_buffer, shared_buffer is copyable (seemingly), but auto_buffer is a bit more efficient. template class shared_buffer { public: @@ -158,8 +158,6 @@ public: protected: buffer_type buffer; }; -//not like auto_buffer, shared_buffer is copyable, but auto_buffer is a bit more efficient. -//packer or/and unpacker who used auto_buffer or shared_buffer as its msg type will be replaceable. //ascs requires that container must take one and only one template argument #if defined(_MSC_VER) || defined(__clang__) || _GLIBCXX_USE_CXX11_ABI diff --git a/include/ascs/config.h b/include/ascs/config.h index c4a5acfc397644e4e40a1e733ca308de691f3867..3a6fe819caf05970d9cca50eab146898d52b69b0 100644 --- a/include/ascs/config.h +++ b/include/ascs/config.h @@ -56,7 +56,6 @@ * In contrast to non_lock_queue, split message_queue into lock_queue and lock_free_queue. * Move container related classes and functions from base.h to container.h. * Improve efficiency in scenarios of low throughput like pingpong test. - * Replaceable packer/unpacker now support replaceable_buffer (an alias of auto_buffer) and shared_buffer to be their message type. * Move class statistic and obj_with_begin_time out of ascs::socket to reduce template tiers. * * 2016.11.1 version 1.1.2 @@ -480,6 +479,8 @@ * statistic.send_msg_sum may be bigger than before (but statistic.send_byte_sum will be the same), see ENHANCEMENTS section for more details. * Not support gcc 4.6 any more, please use st_asio_wrapper instead. * Make function tcp::socket_base::reset to be virtual. + * Rename replaceable_unpacker to unpacker2, replaceable_udp_unpacker to udp_unpacker2, replaceable_packer to packer2, because their names confuse + * users, any packer or unpacker is replaceable for those packer or unpacker that has the same msg_type. * * HIGHLIGHT: * Make client_socket_base be able to call multi_client_base (via i_matrix) like server_socket_base call server_base (via i_server), @@ -503,6 +504,9 @@ * direct_send_msg and direct_sync_send_msg support batch operation. * Introduce virtual function type_name() and type_id() to ascs::socket, they can identify whether a given two ascs::socket has the same type. * force_shutdown and graceful_shutdown support reconnecting even if the link has broken. + * Extract function start_listen from current implementations. + * Support concurrency hint for io_context if possible. + * Demonstrate how to accept just one client at server endpoint in demo echo_server. * * DELETION: * diff --git a/include/ascs/ext/ext.h b/include/ascs/ext/ext.h index 5d96e798de041f67717cbc6851acbd70eed5acb8..2b447455fadd2dc78ec887fbbf1564c5e7c084d4 100644 --- a/include/ascs/ext/ext.h +++ b/include/ascs/ext/ext.h @@ -42,7 +42,7 @@ static_assert(ASCS_MSG_BUFFER_SIZE > 0, "message buffer size must be bigger than namespace ascs { namespace ext { -//implement i_buffer interface, then string_buffer can be wrapped by replaceable_buffer +//implement i_buffer interface, then string_buffer can be wrapped by auto_buffer or shared_buffer class string_buffer : public std::string, public i_buffer { public: diff --git a/include/ascs/ext/packer.h b/include/ascs/ext/packer.h index de425e30c96d448bc9f20ec79d41ba6084d95227..e7cf868826721870bbcc85c3f20ce892617be5d9 100644 --- a/include/ascs/ext/packer.h +++ b/include/ascs/ext/packer.h @@ -138,9 +138,9 @@ public: }; //protocol: length + body -//T can be replaceable_buffer (an alias of auto_buffer) or shared_buffer, the latter makes output messages seemingly copyable. -template -class replaceable_packer : public i_packer +//T can be auto_buffer or shared_buffer, the latter makes output messages seemingly copyable. +template> +class packer2 : public i_packer { private: typedef i_packer super; diff --git a/include/ascs/ext/unpacker.h b/include/ascs/ext/unpacker.h index 851e13a40f60a5e4c721b7793104e5b591571adf..c4bf765d2c771ed8c6f69c5d064a58fa582ce3f7 100644 --- a/include/ascs/ext/unpacker.h +++ b/include/ascs/ext/unpacker.h @@ -146,9 +146,9 @@ protected: }; //protocol: length + body -//T can be replaceable_buffer (an alias of auto_buffer) or shared_buffer, the latter makes output messages seemingly copyable, -template -class replaceable_unpacker : public ascs::i_unpacker +//T can be auto_buffer or shared_buffer, the latter makes output messages seemingly copyable. +template> +class unpacker2 : public ascs::i_unpacker { private: typedef ascs::i_unpacker super; @@ -177,9 +177,9 @@ protected: }; //protocol: UDP has message boundary, so we don't need a specific protocol to unpack it. -//T can be replaceable_buffer (an alias of auto_buffer) or shared_buffer, the latter makes output messages seemingly copyable. -template -class replaceable_udp_unpacker : public ascs::i_unpacker +//T can be auto_buffer or shared_buffer, the latter makes output messages seemingly copyable. +template> +class udp_unpacker2 : public ascs::i_unpacker { private: typedef ascs::i_unpacker super;