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

rpc_address: remove c interface of dsn_address_t #4

Merged
merged 7 commits into from Apr 11, 2018

Conversation

shengofsun
Copy link
Contributor

merge the structure of dsn_address_t to rpc_address.h, make code
less confused

merge the structure of dsn_address_t to rpc_address.h, make code
less confused
class rpc_address
{
public:
static const rpc_address sInvalid;
Copy link
Contributor

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?

}
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(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this?

@@ -57,15 +57,16 @@

Copy link
Contributor

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.

_addr.group.group = (uint64_t)addr;
}

rpc_address rpc_address::clone() const
Copy link
Contributor

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?

Copy link
Contributor Author

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
@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


namespace dsn {
const rpc_address rpc_group_address::_invalid;
}
const rpc_address rpc_address::sInvalid;

#ifdef _WIN32
Copy link
Contributor

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.

// 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
Copy link
Member

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释里都写了让看message_header的Attention了……
改倒是可以改。但是,我就是看着留洋的注释搞明白的,没觉得哪里有容易不明白的地方……

Copy link
Member

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.

Copy link
Contributor Author

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 is a POD type
// see@ Attention of message_header

// release_buffer_header();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数没有真正被使用过,所以只是为了帮助写注释?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对的

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
Copy link
Member

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”

@@ -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
Copy link
Member

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

@shengofsun
Copy link
Contributor Author

@qinzuoyan comments are fixed

@qinzuoyan
Copy link
Member

@shengofsun more comments.

header = (message_header *)ptr;
}

void message_ex::release_buffer_header()
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前用这种方式注释这段代码没问题,你有了placement new,当然得有显式的析构函数。不加这段代码才容易让人感到疑惑

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 建议把这段注释全删了
  2. copy_and_prepare_send 的 clone_content 参数也删了,我搜了一下没有哪里有用除了 false 以外的参数。并且改名叫 forward_to_send,因为它只在 rpc_engine::forward 里用。
  3. 加以下注释在 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[]>?

Copy link
Contributor Author

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上再纠结下去,超纲了。

@qinzuoyan
Copy link
Member

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants