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

Method Connect

src/brpc/stream.cpp:238–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236}
237
238int Stream::Connect(Socket* ptr, const timespec*,
239 int (*on_connect)(int, int, void *), void *data) {
240 CHECK_EQ(ptr->id(), _id);
241 bthread_mutex_lock(&_connect_mutex);
242 if (_connect_meta.on_connect != NULL) {
243 CHECK(false) << "Connect is supposed to be called once";
244 bthread_mutex_unlock(&_connect_mutex);
245 return -1;
246 }
247 _connect_meta.on_connect = on_connect;
248 _connect_meta.arg = data;
249 if (_connected) {
250 ConnectMeta* meta = new ConnectMeta;
251 meta->on_connect = _connect_meta.on_connect;
252 meta->arg = _connect_meta.arg;
253 meta->ec = _connect_meta.ec;
254 bthread_mutex_unlock(&_connect_mutex);
255 bthread_t tid;
256 if (bthread_start_urgent(&tid, &BTHREAD_ATTR_NORMAL, RunOnConnect, meta) != 0) {
257 LOG(FATAL) << "Fail to start bthread, " << berror();
258 RunOnConnect(meta);
259 }
260 return 0;
261 }
262 bthread_mutex_unlock(&_connect_mutex);
263 return 0;
264}
265
266void Stream::SetConnected() {
267 return SetConnected(NULL);

Callers

nothing calls this directly

Calls 5

bthread_mutex_lockFunction · 0.85
bthread_mutex_unlockFunction · 0.85
bthread_start_urgentFunction · 0.85
berrorFunction · 0.85
idMethod · 0.45

Tested by

no test coverage detected