Skip to content

Commit

Permalink
Merge pull request #181 from zd-double/no-boost
Browse files Browse the repository at this point in the history
Add create_with_init option in RpcChannelOptions
  • Loading branch information
zd-double authored Jan 20, 2017
2 parents d601229 + d5c3390 commit cebb305
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/sofa/pbrpc/rpc_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ RpcChannel::RpcChannel(RpcClient* rpc_client,
const RpcChannelOptions& options)
: _impl(new SimpleRpcChannelImpl(rpc_client->impl(), server_address, options))
{
_impl->Init();
if (options.create_with_init)
{
_impl->Init();
}
}

RpcChannel::RpcChannel(RpcClient* rpc_client,
Expand All @@ -27,23 +30,37 @@ RpcChannel::RpcChannel(RpcClient* rpc_client,
std::ostringstream os;
os << server_ip << ":" << server_port;
_impl.reset(new SimpleRpcChannelImpl(rpc_client->impl(), os.str(), options));
_impl->Init();
if (options.create_with_init)
{
_impl->Init();
}
}

RpcChannel::RpcChannel(RpcClient* rpc_client,
const std::vector<std::string>& address_list,
const RpcChannelOptions& options)
: _impl(new DynamicRpcChannelImpl(rpc_client->impl(), address_list, options))
{
_impl->Init();
if (options.create_with_init)
{
_impl->Init();
}
}

RpcChannel::RpcChannel(RpcClient* rpc_client,
AddressProvider* address_provider,
const RpcChannelOptions& options)
: _impl(new DynamicRpcChannelImpl(rpc_client->impl(), address_provider, options))
{
_impl->Init();
if (options.create_with_init)
{
_impl->Init();
}
}

bool RpcChannel::Init()
{
return _impl->Init();
}

RpcChannel::~RpcChannel()
Expand Down
13 changes: 13 additions & 0 deletions src/sofa/pbrpc/rpc_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ struct RpcChannelOptions {
// Value 0 means no limit, default value is 0.
uint32 server_load_capacity;

// If initialize the RpcChannel in construct function, default is true.
// If create_with_init is false, RpcChannel should be initialized by calling Init().
bool create_with_init;

RpcChannelOptions()
: connect_timeout(10)
, server_load_capacity(0)
, create_with_init(true)
{}
};

Expand Down Expand Up @@ -93,6 +98,14 @@ class RpcChannel : public google::protobuf::RpcChannel
AddressProvider* address_provider,
const RpcChannelOptions& options = RpcChannelOptions());

// Initialize RpcChannel.
// For single server point, it will resolve server address in this function,
// and if resolve server address succeed return true, otherwise return false.
// For multiple server points, it will update internal server list and
// register detect task. After all of these are completed return true, and
// never return false.
bool Init();

// Destructor.
virtual ~RpcChannel();

Expand Down

0 comments on commit cebb305

Please sign in to comment.