| 1512 | } |
| 1513 | |
| 1514 | int 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 | |
| 1537 | void Socket::CheckConnectedAndKeepWrite(int fd, int err, void* data) { |
| 1538 | butil::fd_guard sockfd(fd); |
nothing calls this directly
no test coverage detected