File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,10 @@ TcpConnectStatus TcpTransport::getTcpConnectStatus() {
67
67
}
68
68
69
69
TcpConnectStatus TcpTransport::waitTcpConnectEvent (int timeoutMillis) {
70
- std::unique_lock<std::mutex> eventLock (m_connectEventLock);
71
70
if (m_tcpConnectStatus == TCP_CONNECT_STATUS_WAIT) {
72
- if (m_connectEvent.wait_for (eventLock, std::chrono::milliseconds (timeoutMillis)) == std::cv_status::timeout) {
71
+ std::unique_lock<std::mutex> eventLock (m_connectEventLock);
72
+ if (!m_connectEvent.wait_for (eventLock, std::chrono::milliseconds (timeoutMillis),
73
+ [&] { return m_tcpConnectStatus != TCP_CONNECT_STATUS_WAIT; })) {
73
74
LOG_INFO (" connect timeout" );
74
75
}
75
76
}
@@ -80,7 +81,7 @@ TcpConnectStatus TcpTransport::waitTcpConnectEvent(int timeoutMillis) {
80
81
void TcpTransport::setTcpConnectEvent (TcpConnectStatus connectStatus) {
81
82
TcpConnectStatus baseStatus = m_tcpConnectStatus.exchange (connectStatus, std::memory_order_relaxed);
82
83
if (baseStatus == TCP_CONNECT_STATUS_WAIT) {
83
- std::unique_lock<std::mutex> eventLock (m_connectEventLock);
84
+ // awake waiting thread
84
85
m_connectEvent.notify_all ();
85
86
}
86
87
}
You can’t perform that action at this time.
0 commit comments