From a73f00f65b534007f746e63fd276a8f59179e5a2 Mon Sep 17 00:00:00 2001 From: neverchanje Date: Sat, 14 Jul 2018 00:13:13 +0800 Subject: [PATCH] rpc: minor refactoring on message parser --- include/dsn/tool-api/message_parser.h | 15 +++++---------- src/core/CMakeLists.txt | 10 +++++++++- src/core/core/network.cpp | 12 ------------ src/core/runtime/CMakeLists.txt | 10 ---------- src/core/tools/common/dsn_message_parser.cpp | 5 ----- src/core/tools/common/dsn_message_parser.h | 2 -- src/core/tools/common/http_message_parser.cpp | 5 ----- src/core/tools/common/http_message_parser.h | 2 -- src/core/tools/common/raw_message_parser.cpp | 4 ---- src/core/tools/common/raw_message_parser.h | 2 -- src/core/tools/common/thrift_message_parser.cpp | 5 ----- src/core/tools/common/thrift_message_parser.h | 2 -- 12 files changed, 14 insertions(+), 60 deletions(-) delete mode 100644 src/core/runtime/CMakeLists.txt diff --git a/include/dsn/tool-api/message_parser.h b/include/dsn/tool-api/message_parser.h index c812c42290..0f0f6b4bba 100644 --- a/include/dsn/tool-api/message_parser.h +++ b/include/dsn/tool-api/message_parser.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -112,24 +113,18 @@ class message_parser : public ref_counter // may be invoked for mutiple times if the message is reused for resending. virtual void prepare_on_send(message_ex *msg) {} -// be compatible with WSABUF on windows and iovec on linux -#ifdef _WIN32 - struct send_buf - { - uint32_t sz; - void *buf; - }; -#else struct send_buf { void *buf; size_t sz; }; -#endif // get max buffer count needed by get_buffers_on_send(). // may be invoked for mutiple times if the message is reused for resending. - virtual int get_buffer_count_on_send(message_ex *msg) = 0; + int get_buffer_count_on_send(message_ex *msg) const + { + return static_cast(msg->buffers.size()); + } // get buffers from message to 'buffers'. // return buffer count used, which must be no more than the return value of diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e8980571c9..be64698fa2 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -3,5 +3,13 @@ set(DSN_IN_CORE "TRUE") add_subdirectory(core) add_subdirectory(perf_counter) add_subdirectory(tools) -add_subdirectory(runtime) add_subdirectory(tests) + +add_library(dsn_runtime STATIC + $ + $ + $ + $ + $ + $ + ) diff --git a/src/core/core/network.cpp b/src/core/core/network.cpp index 8205cead6e..ccf789e524 100644 --- a/src/core/core/network.cpp +++ b/src/core/core/network.cpp @@ -24,18 +24,6 @@ * THE SOFTWARE. */ -/* - * Description: - * What is this file about? - * - * Revision history: - * xxxx-xx-xx, author, first version - * xxxx-xx-xx, author, fix bug about xxx - */ - -#ifdef _WIN32 -#include -#endif #include #include #include "message_parser_manager.h" diff --git a/src/core/runtime/CMakeLists.txt b/src/core/runtime/CMakeLists.txt deleted file mode 100644 index 1208568662..0000000000 --- a/src/core/runtime/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required(VERSION 2.8.8) - -add_library(dsn_runtime STATIC - $ - $ - $ - $ - $ - $ - ) diff --git a/src/core/tools/common/dsn_message_parser.cpp b/src/core/tools/common/dsn_message_parser.cpp index 98c50a5ac9..a15654846b 100644 --- a/src/core/tools/common/dsn_message_parser.cpp +++ b/src/core/tools/common/dsn_message_parser.cpp @@ -145,11 +145,6 @@ void dsn_message_parser::prepare_on_send(message_ex *msg) } } -int dsn_message_parser::get_buffer_count_on_send(message_ex *msg) -{ - return (int)msg->buffers.size(); -} - int dsn_message_parser::get_buffers_on_send(message_ex *msg, /*out*/ send_buf *buffers) { int i = 0; diff --git a/src/core/tools/common/dsn_message_parser.h b/src/core/tools/common/dsn_message_parser.h index 8054cabc92..6edf83012b 100644 --- a/src/core/tools/common/dsn_message_parser.h +++ b/src/core/tools/common/dsn_message_parser.h @@ -53,8 +53,6 @@ class dsn_message_parser : public message_parser virtual void prepare_on_send(message_ex *msg) override; - virtual int get_buffer_count_on_send(message_ex *msg) override; - virtual int get_buffers_on_send(message_ex *msg, /*out*/ send_buf *buffers) override; private: diff --git a/src/core/tools/common/http_message_parser.cpp b/src/core/tools/common/http_message_parser.cpp index 179201f643..6982680583 100644 --- a/src/core/tools/common/http_message_parser.cpp +++ b/src/core/tools/common/http_message_parser.cpp @@ -405,11 +405,6 @@ void http_message_parser::prepare_on_send(message_ex *msg) buffers.emplace_back(blob(std::move(header_holder), header_len)); } -int http_message_parser::get_buffer_count_on_send(message_ex *msg) -{ - return (int)msg->buffers.size(); -} - int http_message_parser::get_buffers_on_send(message_ex *msg, send_buf *buffers) { auto &msg_header = msg->header; diff --git a/src/core/tools/common/http_message_parser.h b/src/core/tools/common/http_message_parser.h index f57fc73e70..26204bc6d3 100644 --- a/src/core/tools/common/http_message_parser.h +++ b/src/core/tools/common/http_message_parser.h @@ -59,8 +59,6 @@ class http_message_parser : public message_parser virtual void prepare_on_send(message_ex *msg) override; - virtual int get_buffer_count_on_send(message_ex *msg) override; - virtual int get_buffers_on_send(message_ex *msg, /*out*/ send_buf *buffers) override; private: diff --git a/src/core/tools/common/raw_message_parser.cpp b/src/core/tools/common/raw_message_parser.cpp index e4e6a72fc2..0803a82716 100644 --- a/src/core/tools/common/raw_message_parser.cpp +++ b/src/core/tools/common/raw_message_parser.cpp @@ -72,8 +72,6 @@ raw_message_parser::raw_message_parser() } } -void raw_message_parser::reset() {} - message_ex *raw_message_parser::get_message_on_receive(message_reader *reader, /*out*/ int &read_next) { @@ -108,8 +106,6 @@ message_ex *raw_message_parser::get_message_on_receive(message_reader *reader, } } -int raw_message_parser::get_buffer_count_on_send(message_ex *msg) { return msg->buffers.size(); } - int raw_message_parser::get_buffers_on_send(message_ex *msg, send_buf *buffers) { // we must skip the message header diff --git a/src/core/tools/common/raw_message_parser.h b/src/core/tools/common/raw_message_parser.h index e3ee3aeea5..4ab9699483 100644 --- a/src/core/tools/common/raw_message_parser.h +++ b/src/core/tools/common/raw_message_parser.h @@ -52,10 +52,8 @@ class raw_message_parser : public message_parser public: raw_message_parser(); virtual ~raw_message_parser() {} - virtual void reset() override; virtual message_ex *get_message_on_receive(message_reader *reader, /*out*/ int &read_next) override; - virtual int get_buffer_count_on_send(message_ex *msg) override; virtual int get_buffers_on_send(message_ex *msg, /*out*/ send_buf *buffers) override; }; } diff --git a/src/core/tools/common/thrift_message_parser.cpp b/src/core/tools/common/thrift_message_parser.cpp index 2325e96311..73c9e57a10 100644 --- a/src/core/tools/common/thrift_message_parser.cpp +++ b/src/core/tools/common/thrift_message_parser.cpp @@ -147,11 +147,6 @@ void thrift_message_parser::prepare_on_send(message_ex *msg) buffers.emplace_back(std::move(end_bb)); } -int thrift_message_parser::get_buffer_count_on_send(message_ex *msg) -{ - return (int)msg->buffers.size(); -} - int thrift_message_parser::get_buffers_on_send(message_ex *msg, /*out*/ send_buf *buffers) { auto &msg_header = msg->header; diff --git a/src/core/tools/common/thrift_message_parser.h b/src/core/tools/common/thrift_message_parser.h index 3bfa96171d..7cf6e9582a 100644 --- a/src/core/tools/common/thrift_message_parser.h +++ b/src/core/tools/common/thrift_message_parser.h @@ -78,8 +78,6 @@ class thrift_message_parser : public message_parser virtual void prepare_on_send(message_ex *msg) override; - virtual int get_buffer_count_on_send(message_ex *msg) override; - virtual int get_buffers_on_send(message_ex *msg, /*out*/ send_buf *buffers) override; public: