ASyncDBConnectionThread now reports back when it looses the connection

This commit is contained in:
eelke 2020-04-04 07:34:31 +02:00
parent d6709a1dea
commit b87f587a40

View file

@ -7,6 +7,7 @@
#include <chrono>
#include <queue>
#include <WinSock2.h>
#include <QDebug>
namespace {
@ -322,6 +323,7 @@ void ASyncDBConnectionThread::doNewCommand()
}
else {
std::string error = m_connection.getErrorMessage();
qDebug() << "Error sending query " << QString::fromStdString(error);
// todo: need to report the error
}
}
@ -353,12 +355,17 @@ bool ASyncDBConnectionThread::consumeResultInput()
else {
// error during consume
auto error_msg = m_connection.getErrorMessage();
qDebug() << "error while communicating with server " << QString::fromStdString(error_msg);
doStateCallback(ASyncDBConnection::State::NotConnected);
finished = true;
stop();
}
return finished;
}
void ASyncDBConnectionThread::waitForResult()
{
#if false
int sock = m_connection.socket();
fd_set readfds;
@ -381,7 +388,8 @@ void ASyncDBConnectionThread::waitForResult()
}
}
#if false
#else
SOCKET sock = static_cast<SOCKET>(m_connection.socket());
Win32Event socket_event(Win32Event::Reset::Manual, Win32Event::Initial::Clear);
long fd = FD_READ | FD_CLOSE;
@ -392,7 +400,7 @@ void ASyncDBConnectionThread::waitForResult()
WaitHandleList whl;
auto wait_result_socket = whl.add(socket_event);
//auto wait_result_stop = whl.add(m_stopEvent);
auto wait_result_stop = whl.add(m_stopEvent);
DWORD res = MsgWaitForMultipleObjectsEx(
whl.count(), // _In_ DWORD nCount,
@ -414,7 +422,7 @@ void ASyncDBConnectionThread::waitForResult()
if (res == wait_result_stop) {
// Send cancel, close connection and terminate thread
cancel();
doStateCallback(State::Terminating);
doStateCallback(ASyncDBConnection::State::Terminating);
finished = true;
}
} // end while