diff --git a/pglablib/ASyncDBConnection.cpp b/pglablib/ASyncDBConnection.cpp index 95d0181..2367595 100644 --- a/pglablib/ASyncDBConnection.cpp +++ b/pglablib/ASyncDBConnection.cpp @@ -7,6 +7,7 @@ #include #include #include +#include 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(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