MCPcopy Create free account
hub / github.com/apache/brpc / InitChannelOptions

Method InitChannelOptions

src/brpc/channel.cpp:179–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177
178
179int Channel::InitChannelOptions(const ChannelOptions* options) {
180 if (options) { // Override default options if user provided one.
181 _options = *options;
182 }
183 const Protocol* protocol = FindProtocol(_options.protocol);
184 if (NULL == protocol || !protocol->support_client()) {
185 LOG(ERROR) << "Channel does not support the protocol";
186 return -1;
187 }
188 if (_options.hc_option.health_check_path.empty()) {
189 _options.hc_option.health_check_path = FLAGS_health_check_path;
190 _options.hc_option.health_check_timeout_ms = FLAGS_health_check_timeout_ms;
191 }
192 auto ret = TransportFactory::ContextInitOrDie(_options.socket_mode, false, &_options);
193 if (ret != 0) {
194 LOG(ERROR) << "Fail to initialize transport context for channel, ret=" << ret;
195 return -1;
196 }
197
198 _serialize_request = protocol->serialize_request;
199 _pack_request = protocol->pack_request;
200 _get_method_name = protocol->get_method_name;
201
202 // Check connection_type
203 if (_options.connection_type == CONNECTION_TYPE_UNKNOWN) {
204 // Save has_error which will be overriden in later assignments to
205 // connection_type.
206 const bool has_error = _options.connection_type.has_error();
207
208 if (protocol->supported_connection_type & CONNECTION_TYPE_SINGLE) {
209 _options.connection_type = CONNECTION_TYPE_SINGLE;
210 } else if (protocol->supported_connection_type & CONNECTION_TYPE_POOLED) {
211 _options.connection_type = CONNECTION_TYPE_POOLED;
212 } else {
213 _options.connection_type = CONNECTION_TYPE_SHORT;
214 }
215 if (has_error) {
216 LOG(ERROR) << "Channel=" << this << " chose connection_type="
217 << _options.connection_type.name() << " for protocol="
218 << _options.protocol.name();
219 }
220 } else {
221 if (!(_options.connection_type & protocol->supported_connection_type)) {
222 LOG(ERROR) << protocol->name << " does not support connection_type="
223 << ConnectionTypeToString(_options.connection_type);
224 return -1;
225 }
226 }
227
228 _preferred_index = get_client_side_messenger()->FindProtocolIndex(_options.protocol);
229 if (_preferred_index < 0) {
230 LOG(ERROR) << "Fail to get index for protocol="
231 << _options.protocol.name();
232 return -1;
233 }
234
235 if (_options.protocol == PROTOCOL_ESP) {
236 if (_options.auth == NULL) {

Callers

nothing calls this directly

Calls 11

FindProtocolFunction · 0.85
ConnectionTypeToStringFunction · 0.85
global_esp_authenticatorFunction · 0.85
TrimWhitespaceFunction · 0.85
support_clientMethod · 0.80
FindProtocolIndexMethod · 0.80
emptyMethod · 0.45
has_errorMethod · 0.45
nameMethod · 0.45
frontMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected