Fix: high cpu loading while waiting for result caused by wrong event selection
Fix: next bug where it wouldn't retrieve all result when using the proper events causing hangs because it didn't loop isbusy.
This commit is contained in:
parent
2502aea9e5
commit
30638b11e5
1 changed files with 24 additions and 19 deletions
|
|
@ -234,11 +234,12 @@ void ASyncDBConnection::Thread::waitForResult()
|
||||||
{
|
{
|
||||||
|
|
||||||
int sock = m_connection.socket();
|
int sock = m_connection.socket();
|
||||||
Win32Event socket_event(Win32Event::Reset::Auto, Win32Event::Initial::Clear);
|
Win32Event socket_event(Win32Event::Reset::Manual, Win32Event::Initial::Clear);
|
||||||
|
|
||||||
long fd = FD_WRITE;
|
long fd = FD_READ | FD_CLOSE;
|
||||||
|
|
||||||
while (true) {
|
bool finished = false;
|
||||||
|
while ( ! finished) {
|
||||||
WSAEventSelect(sock, socket_event.handle(), fd);
|
WSAEventSelect(sock, socket_event.handle(), fd);
|
||||||
|
|
||||||
WaitHandleList whl;
|
WaitHandleList whl;
|
||||||
|
|
@ -253,8 +254,12 @@ void ASyncDBConnection::Thread::waitForResult()
|
||||||
0 // _In_ DWORD dwFlags
|
0 // _In_ DWORD dwFlags
|
||||||
);
|
);
|
||||||
if (res == wait_result_socket) {
|
if (res == wait_result_socket) {
|
||||||
|
WSANETWORKEVENTS net_events;
|
||||||
|
WSAEnumNetworkEvents(sock, socket_event.handle(), &net_events);
|
||||||
|
|
||||||
|
if (net_events.lNetworkEvents & FD_READ) {
|
||||||
if (m_connection.consumeInput()) {
|
if (m_connection.consumeInput()) {
|
||||||
if ( ! m_connection.isBusy()) {
|
while ( ! finished && ! m_connection.isBusy()) {
|
||||||
auto res(m_connection.getResult());
|
auto res(m_connection.getResult());
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lg(m_commandQueue.m_mutex);
|
std::lock_guard<std::mutex> lg(m_commandQueue.m_mutex);
|
||||||
|
|
@ -262,8 +267,7 @@ void ASyncDBConnection::Thread::waitForResult()
|
||||||
if (res == nullptr) {
|
if (res == nullptr) {
|
||||||
m_commandQueue.m_queue.pop();
|
m_commandQueue.m_queue.pop();
|
||||||
doStateCallback(State::Connected);
|
doStateCallback(State::Connected);
|
||||||
break; // leave the while loop
|
finished = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,11 +280,12 @@ void ASyncDBConnection::Thread::waitForResult()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (res == wait_result_stop) {
|
if (res == wait_result_stop) {
|
||||||
// Send cancel, close connection and terminate thread
|
// Send cancel, close connection and terminate thread
|
||||||
cancel();
|
cancel();
|
||||||
doStateCallback(State::Terminating);
|
doStateCallback(State::Terminating);
|
||||||
break;
|
finished = true;
|
||||||
}
|
}
|
||||||
} // end while
|
} // end while
|
||||||
// When last result received, remove command from queue
|
// When last result received, remove command from queue
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue