@@ -41,10 +41,13 @@ typedef std::map<ChannelBase*, Socket*> ChannelToIdMap;
4141class SubChannel : public SocketUser {
4242public:
4343 ChannelBase* chan;
44+ ChannelOwnership ownership;
4445
4546 // internal channel is deleted after the fake Socket is SetFailed
4647 void BeforeRecycle (Socket*) {
47- delete chan;
48+ if (ownership == OWNS_CHANNEL) {
49+ delete chan;
50+ }
4851 delete this ;
4952 }
5053
@@ -84,6 +87,7 @@ class ChannelBalancer : public SharedLoadBalancer {
8487 ~ChannelBalancer ();
8588 int Init (const char * lb_name);
8689 int AddChannel (ChannelBase* sub_channel, const std::string& tag,
90+ ChannelOwnership ownership,
8791 SelectiveChannel::ChannelHandle* handle);
8892 void RemoveAndDestroyChannel (const SelectiveChannel::ChannelHandle& handle);
8993 int SelectChannel (const LoadBalancer::SelectIn& in, SelectOut* out);
@@ -168,7 +172,9 @@ int ChannelBalancer::Init(const char* lb_name) {
168172 return SharedLoadBalancer::Init (lb_name);
169173}
170174
171- int ChannelBalancer::AddChannel (ChannelBase* sub_channel, const std::string& tag,
175+ int ChannelBalancer::AddChannel (ChannelBase* sub_channel,
176+ const std::string& tag,
177+ ChannelOwnership ownership,
172178 SelectiveChannel::ChannelHandle* handle) {
173179 if (NULL == sub_channel) {
174180 LOG (ERROR) << " Parameter[sub_channel] is NULL" ;
@@ -185,6 +191,7 @@ int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag
185191 return -1 ;
186192 }
187193 sub_chan->chan = sub_channel;
194+ sub_chan->ownership = ownership;
188195 SocketId sock_id;
189196 SocketOptions options;
190197 options.user = sub_chan;
@@ -215,7 +222,7 @@ int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag
215222 return -1 ;
216223 }
217224 // The health-check-related reference has been held on created.
218- _chan_map[sub_channel]= ptr.get ();
225+ _chan_map[sub_channel] = ptr.get ();
219226 if (handle) {
220227 handle->id = sock_id;
221228 handle->tag = tag;
@@ -532,20 +539,15 @@ bool SelectiveChannel::initialized() const {
532539}
533540
534541int SelectiveChannel::AddChannel (ChannelBase* sub_channel,
535- ChannelHandle* handle) {
536- return AddChannel (sub_channel, " " , handle);
537- }
538-
539- int SelectiveChannel::AddChannel (ChannelBase* sub_channel,
540- const std::string& tag,
542+ const SubChannelOptions& option,
541543 ChannelHandle* handle) {
542544 schan::ChannelBalancer* lb =
543545 static_cast <schan::ChannelBalancer*>(_chan._lb .get ());
544546 if (lb == NULL ) {
545547 LOG (ERROR) << " You must call Init() to initialize a SelectiveChannel" ;
546548 return -1 ;
547549 }
548- return lb->AddChannel (sub_channel, tag, handle);
550+ return lb->AddChannel (sub_channel, option. tag , option. ownership , handle);
549551}
550552
551553void SelectiveChannel::RemoveAndDestroyChannel (const ChannelHandle& handle) {
0 commit comments