Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

rpc: minor refactoring on message parser #131

Merged
merged 1 commit into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions include/dsn/tool-api/message_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <dsn/utility/ports.h>
#include <dsn/utility/singleton.h>
#include <dsn/tool-api/task_spec.h>
#include <dsn/tool-api/rpc_message.h>
#include <dsn/utility/autoref_ptr.h>
#include <dsn/utility/utils.h>
#include <dsn/utility/blob.h>
Expand Down Expand Up @@ -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<int>(msg->buffers.size());
}

// get buffers from message to 'buffers'.
// return buffer count used, which must be no more than the return value of
Expand Down
10 changes: 9 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<TARGET_OBJECTS:dsn.core>
$<TARGET_OBJECTS:dsn.nfs>
$<TARGET_OBJECTS:dsn.perf_counter>
$<TARGET_OBJECTS:dsn.tools.common>
$<TARGET_OBJECTS:dsn.tools.hpc>
$<TARGET_OBJECTS:dsn.tools.simulator>
)
12 changes: 0 additions & 12 deletions src/core/core/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Winsock2.h>
#endif
#include <dsn/tool-api/network.h>
#include <dsn/utility/factory_store.h>
#include "message_parser_manager.h"
Expand Down
10 changes: 0 additions & 10 deletions src/core/runtime/CMakeLists.txt

This file was deleted.

5 changes: 0 additions & 5 deletions src/core/tools/common/dsn_message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/core/tools/common/dsn_message_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions src/core/tools/common/http_message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/core/tools/common/http_message_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions src/core/tools/common/raw_message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/core/tools/common/raw_message_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand Down
5 changes: 0 additions & 5 deletions src/core/tools/common/thrift_message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/core/tools/common/thrift_message_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down