rpc_address: remove c interface of dsn_address_t #4
Conversation
merge the structure of dsn_address_t to rpc_address.h, make code less confused
include/dsn/tool-api/rpc_address.h
Outdated
class rpc_address | ||
{ | ||
public: | ||
static const rpc_address sInvalid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use camel case naming here? May invalid_address
be a preferred name?
include/dsn/tool-api/rpc_address.h
Outdated
} | ||
rpc_uri_address *uri_address() const { return (rpc_uri_address *)(uintptr_t)_addr.uri.uri; } | ||
bool is_invalid() const { return _addr.v4.type == HOST_TYPE_INVALID; } | ||
void set_invalid() { clear(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this?
src/core/core/address.cpp
Outdated
@@ -57,15 +57,16 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this file to "rpc_address.cpp"? Since this file contains only rpc_address
, no other class exists.
src/core/core/address.cpp
Outdated
_addr.group.group = (uint64_t)addr; | ||
} | ||
|
||
rpc_address rpc_address::clone() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see any difference between clone
and operator=
. Even if they are implemented differently, they are supposed to be the same. Remove clone
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clone is used for uri_resolver in the old code, currently it's indeed useless. Let's remove it.
remove redudant clear function, rename sInvalid to s_invalid_address
src/core/core/rpc_message.cpp
Outdated
@@ -214,6 +214,13 @@ message_ex::message_ex() | |||
|
|||
message_ex::~message_ex() | |||
{ | |||
// when recv a request, message_header is hidden ahead of buffer(see@create_receive_message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what does "hidden ahead of buffer" mean? Could you make it clear?
BTW, don't use abbreviation like "recv" in your comment. Always be careful of your grammar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/core/core/address.cpp
Outdated
|
||
namespace dsn { | ||
const rpc_address rpc_group_address::_invalid; | ||
} | ||
const rpc_address rpc_address::sInvalid; | ||
|
||
#ifdef _WIN32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should no longer support win32. See L71, L247, L256 and L36 of this file, L81 of src/core/tests/address.cpp.
src/core/core/rpc_message.cpp
Outdated
// then new request's header will be invalid. | ||
// | ||
// so we don't release_buffer_header(). | ||
// however, this won't lead to any memory leak problems as long as the header is a POD type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里说"the header is a POD type"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释里都写了让看message_header的Attention了……
改倒是可以改。但是,我就是看着留洋的注释搞明白的,没觉得哪里有容易不明白的地方……
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还是写清楚点吧:however, this won't lead to any memory leak problems as long as the header can be thought of as POD type (because the from_address must be IPv4 address), refer to the ATTENTION of message_header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
后来这个地方改过了,你看看新的注释,应该也能说清楚了
src/core/core/rpc_message.cpp
Outdated
// however, this won't lead to any memory leak problems as long as the header is a POD type | ||
// see@ Attention of message_header | ||
|
||
// release_buffer_header(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数没有真正被使用过,所以只是为了帮助写注释?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对的
src/core/core/rpc_message.cpp
Outdated
header = (message_header *)ptr; | ||
} | ||
|
||
void message_ex::release_buffer_header() | ||
{ | ||
// message_header contain variable that is not POD-type, so we call these variable's destructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也说“message_header contain variable that is not POD-type”
src/core/core/rpc_message.cpp
Outdated
@@ -465,9 +478,18 @@ void message_ex::prepare_buffer_header() | |||
this->_rw_offset = (int)sizeof(message_header); | |||
this->buffers.push_back(buffer); | |||
|
|||
// here, we should call placement new, because message_header contain variable that is not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里又说“message_header contain variable that is not POD-type”,与上面的注释不一致,容易confused
@qinzuoyan comments are fixed |
@shengofsun more comments. |
header = (message_header *)ptr; | ||
} | ||
|
||
void message_ex::release_buffer_header() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this, I don't see any place using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当前用这种方式注释这段代码没问题,你有了placement new,当然得有显式的析构函数。不加这段代码才容易让人感到疑惑
src/core/core/rpc_message.cpp
Outdated
@@ -214,6 +214,19 @@ message_ex::message_ex() | |||
|
|||
message_ex::~message_ex() | |||
{ | |||
// when receiving a request, the lifetime of message_header object is managed by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 建议把这段注释全删了
- 把
copy_and_prepare_send
的 clone_content 参数也删了,我搜了一下没有哪里有用除了 false 以外的参数。并且改名叫forward_to_send
,因为它只在rpc_engine::forward
里用。 - 加以下注释在
message_ex::buffers
上面:
// For sending,
// buffers[0] = (memory of message_header),
// buffers[1] = (memory of request content).
//
// For receiving,
// buffers[0] = (memory of message content),
// (memory of message_header) = buffers[0] - sizeof(memory_header).
//
// In the case where request is forwarded from one server to another, the received request
// as well as its message header will be entirely moved into the new request to send.
// \see message_ex::copy_and_prepare_send and rpc_engine::forward
原来底下这段注释的目的是解释 message_header 使用 dsn::blob 来共享内存的原因,但如果只是为了 forward,我没有理解为什么还要用 blob?可不可以用 unique_ptr<char[]>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
再提个pr来改吧,这个pr是rpc_address相关的,以及由于rpc_address改动而对潜在问题的相关改动。
在message上再纠结下去,超纲了。
LGTM |
merge the structure of dsn_address_t to rpc_address.h, make code
less confused