提交 2158fe21 编写于 作者: Y youngwolf

Continue last commit.

上级 1865da17
......@@ -25,7 +25,15 @@
//2-fixed length packer and unpacker
//3-prefix and/or suffix packer and unpacker
#if 1 == PACKER_UNPACKER_TYPE
#if 0 == PACKER_UNPACKER_TYPE
#define ASCS_HUGE_MSG
#define ASCS_MSG_BUFFER_SIZE 1000000
#define ASCS_MAX_SEND_BUF (10 * ASCS_MSG_BUFFER_SIZE)
#define ASCS_MAX_RECV_BUF (10 * ASCS_MSG_BUFFER_SIZE)
#define ASCS_DEFAULT_UNPACKER flexible_unpacker
//this unpacker only pre-allocated a buffer of 4000 bytes, but it can parse messages up to ST_ASIO_MSG_BUFFER_SIZE (here is 1000000) bytes,
//it works as the default unpacker for messages <= 4000, otherwise, it works as non_copy_unpacker
#elif 1 == PACKER_UNPACKER_TYPE
#define ASCS_DEFAULT_PACKER packer2<unique_buffer<std::string>, std::string>
#define ASCS_DEFAULT_UNPACKER unpacker2<unique_buffer<std::string>>
#elif 2 == PACKER_UNPACKER_TYPE
......
......@@ -25,7 +25,15 @@
//2-fixed length packer and unpacker
//3-prefix and/or suffix packer and unpacker
#if 1 == PACKER_UNPACKER_TYPE
#if 0 == PACKER_UNPACKER_TYPE
#define ASCS_HUGE_MSG
#define ASCS_MSG_BUFFER_SIZE 1000000
#define ASCS_MAX_SEND_BUF (10 * ASCS_MSG_BUFFER_SIZE)
#define ASCS_MAX_RECV_BUF (10 * ASCS_MSG_BUFFER_SIZE)
#define ASCS_DEFAULT_UNPACKER flexible_unpacker
//this unpacker only pre-allocated a buffer of 4000 bytes, but it can parse messages up to ST_ASIO_MSG_BUFFER_SIZE (here is 1000000) bytes,
//it works as the default unpacker for messages <= 4000, otherwise, it works as non_copy_unpacker
#elif 1 == PACKER_UNPACKER_TYPE
#define ASCS_DEFAULT_PACKER packer2<unique_buffer<std::string>, std::string>
#define ASCS_DEFAULT_UNPACKER unpacker2<unique_buffer<std::string>>
#elif 2 == PACKER_UNPACKER_TYPE
......
......@@ -379,7 +379,7 @@ protected:
//protocol: length + body
//T can be unique_buffer<std::string> or shared_buffer<std::string>, the latter makes output messages seemingly copyable.
template<typename T = shared_buffer<std::string>>
template<typename T = shared_buffer<std::string>, typename Unpacker = unpacker>
class unpacker2 : public ascs::i_unpacker<T>
{
private:
......@@ -390,10 +390,10 @@ public:
virtual void dump_left_data() const {unpacker_.dump_left_data();}
virtual bool parse_msg(size_t bytes_transferred, typename super::container_type& msg_can)
{
unpacker::container_type tmp_can;
typename Unpacker::container_type tmp_can;
unpacker_.stripped(this->stripped());
auto unpack_ok = unpacker_.parse_msg(bytes_transferred, tmp_can);
do_something_to_all(tmp_can, [&msg_can](unpacker::msg_type& item) {msg_can.emplace_back(new std::string(std::move(item)));});
do_something_to_all(tmp_can, [&msg_can](typename Unpacker::msg_type& item) {msg_can.emplace_back(new std::string(std::move(item)));});
//if unpacking failed, successfully parsed msgs will still returned via msg_can(sticky package), please note.
return unpack_ok;
......@@ -408,7 +408,7 @@ public:
virtual size_t raw_data_len(typename super::msg_ctype& msg) const {return this->stripped() ? msg.size() : msg.size() - ASCS_HEAD_LEN;}
protected:
unpacker unpacker_;
Unpacker unpacker_;
};
//protocol: UDP has message boundary, so we don't need a specific protocol to unpack it.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册