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

Method KeepWriteIfConnected

src/brpc/socket.cpp:1514–1535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1512}
1513
1514int Socket::KeepWriteIfConnected(int fd, int err, void* data) {
1515 WriteRequest* req = static_cast<WriteRequest*>(data);
1516 Socket* s = req->get_socket();
1517 if (err == 0 && s->ssl_state() == SSL_CONNECTING) {
1518 // Run ssl connect in a new bthread to avoid blocking
1519 // the current bthread (thus blocking the EventDispatcher)
1520 bthread_t th;
1521 std::unique_ptr<google::protobuf::Closure> thrd_func(
1522 NewCallback(CheckConnectedAndKeepWrite, fd, err, data));
1523 bthread_attr_t attr = BTHREAD_ATTR_NORMAL;
1524 bthread_attr_set_name(&attr, "CheckConnectedAndKeepWrite");
1525 if ((err = bthread_start_background(&th, &attr, RunClosure, thrd_func.get())) == 0) {
1526 thrd_func.release();
1527 return 0;
1528 } else {
1529 PLOG(ERROR) << "Fail to start bthread";
1530 // Fall through with non zero `err'
1531 }
1532 }
1533 CheckConnectedAndKeepWrite(fd, err, data);
1534 return 0;
1535}
1536
1537void Socket::CheckConnectedAndKeepWrite(int fd, int err, void* data) {
1538 butil::fd_guard sockfd(fd);

Callers

nothing calls this directly

Calls 5

NewCallbackFunction · 0.85
bthread_attr_set_nameFunction · 0.85
bthread_start_backgroundFunction · 0.85
getMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected