mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-27 00:31:02 +08:00
Check connection in GUI
This commit is contained in:
parent
e4879d46dd
commit
b1e6bef056
@ -107,6 +107,12 @@ public:
|
||||
|
||||
void setState(ConnectionState state){m_state=state;}
|
||||
ConnectionState state() const{return m_state;}
|
||||
|
||||
bool isDisconnected() const
|
||||
{
|
||||
return m_state == CONNECTION_STATE_UNKNOWN ||
|
||||
m_state == CONNECTION_STATE_DISCONNECTED;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // EASY________SOCKET_________H
|
||||
|
@ -67,7 +67,7 @@
|
||||
#include <QSignalBlocker>
|
||||
#include <QDebug>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QToolButton>
|
||||
#include <QWidgetAction>
|
||||
#include <QMessageBox>
|
||||
#include <QLineEdit>
|
||||
@ -790,6 +790,20 @@ void EasyMainWindow::saveSettingsAndGeometry()
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void EasyMainWindow::setDisconnected()
|
||||
{
|
||||
QMessageBox::warning(this, "Warning", "Application was disconnected", QMessageBox::Close);
|
||||
EASY_GLOBALS.connected = false;
|
||||
m_captureAction->setEnabled(false);
|
||||
SET_ICON(m_connectAction, ":/Connection");
|
||||
|
||||
m_eventTracingEnableAction->setEnabled(false);
|
||||
m_eventTracingPriorityAction->setEnabled(false);
|
||||
|
||||
emit EASY_GLOBALS.events.connectionChanged(false);
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void EasyMainWindow::onListenerTimerTimeout()
|
||||
@ -837,18 +851,11 @@ void EasyMainWindow::onListenerDialogClose(int)
|
||||
|
||||
if (!m_listener.connected())
|
||||
{
|
||||
QMessageBox::warning(this, "Warning", "Application was disconnected", QMessageBox::Close);
|
||||
EASY_GLOBALS.connected = false;
|
||||
m_captureAction->setEnabled(false);
|
||||
SET_ICON(m_connectAction, ":/Connection");
|
||||
|
||||
m_eventTracingEnableAction->setEnabled(false);
|
||||
m_eventTracingPriorityAction->setEnabled(false);
|
||||
|
||||
emit EASY_GLOBALS.events.connectionChanged(false);
|
||||
setDisconnected();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void EasyMainWindow::onFileReaderTimeout()
|
||||
@ -860,7 +867,7 @@ void EasyMainWindow::onFileReaderTimeout()
|
||||
{
|
||||
static_cast<EasyTreeWidget*>(m_treeWidget->widget())->clearSilent(true);
|
||||
|
||||
::profiler::SerializedData serialized_blocks;
|
||||
::profiler::SerializedData serialized_blocks;
|
||||
::profiler::SerializedData serialized_descriptors;
|
||||
::profiler::descriptors_list_t descriptors;
|
||||
::profiler::blocks_t blocks;
|
||||
@ -1311,15 +1318,7 @@ void EasyMainWindow::onGetBlockDescriptionsClicked(bool)
|
||||
|
||||
if (!m_listener.connected())
|
||||
{
|
||||
QMessageBox::warning(this, "Warning", "Application was disconnected", QMessageBox::Close);
|
||||
EASY_GLOBALS.connected = false;
|
||||
m_captureAction->setEnabled(false);
|
||||
SET_ICON(m_connectAction, ":/Connection");
|
||||
|
||||
m_eventTracingEnableAction->setEnabled(false);
|
||||
m_eventTracingPriorityAction->setEnabled(false);
|
||||
|
||||
emit EASY_GLOBALS.events.connectionChanged(false);
|
||||
setDisconnected();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1395,7 +1394,7 @@ bool EasySocketListener::connect(const char* _ipaddress, uint16_t _port, profile
|
||||
|
||||
if (bytes == -1)
|
||||
{
|
||||
if (m_easySocket.state() == EasySocket::CONNECTION_STATE_DISCONNECTED)
|
||||
if (m_easySocket.isDisconnected())
|
||||
return false;
|
||||
bytes = 0;
|
||||
continue;
|
||||
@ -1417,7 +1416,7 @@ bool EasySocketListener::connect(const char* _ipaddress, uint16_t _port, profile
|
||||
|
||||
if (bytes == -1)
|
||||
{
|
||||
if (m_easySocket.state() == EasySocket::CONNECTION_STATE_DISCONNECTED)
|
||||
if (m_easySocket.isDisconnected())
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
@ -1441,6 +1440,10 @@ void EasySocketListener::startCapture()
|
||||
profiler::net::Message request(profiler::net::MESSAGE_TYPE_REQUEST_START_CAPTURE);
|
||||
m_easySocket.send(&request, sizeof(request));
|
||||
|
||||
if(m_easySocket.isDisconnected() ){
|
||||
m_bConnected.store(false, ::std::memory_order_release);
|
||||
}
|
||||
|
||||
m_regime = LISTENER_CAPTURE;
|
||||
m_thread = ::std::move(::std::thread(&EasySocketListener::listenCapture, this));
|
||||
}
|
||||
@ -1453,6 +1456,10 @@ void EasySocketListener::stopCapture()
|
||||
profiler::net::Message request(profiler::net::MESSAGE_TYPE_REQUEST_STOP_CAPTURE);
|
||||
m_easySocket.send(&request, sizeof(request));
|
||||
|
||||
if(m_easySocket.isDisconnected() ){
|
||||
m_bConnected.store(false, ::std::memory_order_release);
|
||||
}
|
||||
|
||||
m_thread.join();
|
||||
|
||||
m_regime = LISTENER_IDLE;
|
||||
@ -1465,6 +1472,10 @@ void EasySocketListener::requestBlocksDescription()
|
||||
profiler::net::Message request(profiler::net::MESSAGE_TYPE_REQUEST_BLOCKS_DESCRIPTION);
|
||||
m_easySocket.send(&request, sizeof(request));
|
||||
|
||||
if(m_easySocket.isDisconnected() ){
|
||||
m_bConnected.store(false, ::std::memory_order_release);
|
||||
}
|
||||
|
||||
m_regime = LISTENER_DESCRIBE;
|
||||
listenDescription();
|
||||
m_regime = LISTENER_IDLE;
|
||||
@ -1490,7 +1501,7 @@ void EasySocketListener::listenCapture()
|
||||
|
||||
if (bytes == -1)
|
||||
{
|
||||
if (m_easySocket.state() == EasySocket::CONNECTION_STATE_DISCONNECTED)
|
||||
if (m_easySocket.isDisconnected())
|
||||
{
|
||||
m_bConnected.store(false, ::std::memory_order_release);
|
||||
isListen = false;
|
||||
@ -1587,7 +1598,7 @@ void EasySocketListener::listenCapture()
|
||||
|
||||
if (bytes == -1)
|
||||
{
|
||||
if (m_easySocket.state() == EasySocket::CONNECTION_STATE_DISCONNECTED)
|
||||
if (m_easySocket.isDisconnected())
|
||||
{
|
||||
m_bConnected.store(false, ::std::memory_order_release);
|
||||
isListen = false;
|
||||
@ -1640,7 +1651,7 @@ void EasySocketListener::listenDescription()
|
||||
|
||||
if (bytes == -1)
|
||||
{
|
||||
if (m_easySocket.state() == EasySocket::CONNECTION_STATE_DISCONNECTED)
|
||||
if (m_easySocket.isDisconnected())
|
||||
{
|
||||
m_bConnected.store(false, ::std::memory_order_release);
|
||||
isListen = false;
|
||||
@ -1720,7 +1731,7 @@ void EasySocketListener::listenDescription()
|
||||
|
||||
if (bytes == -1)
|
||||
{
|
||||
if (m_easySocket.state() == EasySocket::CONNECTION_STATE_DISCONNECTED)
|
||||
if (m_easySocket.isDisconnected())
|
||||
{
|
||||
m_bConnected.store(false, ::std::memory_order_release);
|
||||
isListen = false;
|
||||
|
@ -263,6 +263,8 @@ private:
|
||||
void loadGeometry();
|
||||
void saveSettingsAndGeometry();
|
||||
|
||||
void setDisconnected();
|
||||
|
||||
}; // END of class EasyMainWindow.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -103,7 +103,7 @@ void EasySocket::flush()
|
||||
|
||||
void EasySocket::checkResult(int result)
|
||||
{
|
||||
// printf("Errno: %s\n", strerror(errno));
|
||||
//printf("Errno: %s\n", strerror(errno));
|
||||
if(result >= 0){
|
||||
m_state = CONNECTION_STATE_SUCCESS;
|
||||
return;
|
||||
@ -117,23 +117,25 @@ void EasySocket::checkResult(int result)
|
||||
const int CONNECTION_ABORTED = WSAECONNABORTED;
|
||||
const int CONNECTION_RESET = WSAECONNRESET;
|
||||
const int CONNECTION_IN_PROGRESS = WSAEINPROGRESS;
|
||||
const int CONNECTION_BROKEN_PIPE = WSAECONNABORTED;
|
||||
#else
|
||||
error_code = errno;
|
||||
const int CONNECTION_ABORTED = ECONNABORTED;
|
||||
const int CONNECTION_RESET = ECONNRESET;
|
||||
const int CONNECTION_IN_PROGRESS = EINPROGRESS;
|
||||
const int CONNECTION_BROKEN_PIPE = EPIPE;
|
||||
#endif
|
||||
|
||||
switch(error_code)
|
||||
{
|
||||
case CONNECTION_ABORTED:
|
||||
case CONNECTION_RESET:
|
||||
case CONNECTION_BROKEN_PIPE:
|
||||
m_state = CONNECTION_STATE_DISCONNECTED;
|
||||
break;
|
||||
case CONNECTION_IN_PROGRESS:
|
||||
m_state = CONNECTION_STATE_IN_PROGRESS;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -193,7 +195,7 @@ int EasySocket::send(const void *buf, size_t nbyte)
|
||||
#ifdef _WIN32
|
||||
res = ::send(m_replySocket, (const char*)buf, (int)nbyte, 0);
|
||||
#else
|
||||
res = ::write(m_replySocket,buf,nbyte);
|
||||
res = ::send(m_replySocket,buf,nbyte,MSG_NOSIGNAL);
|
||||
#endif
|
||||
checkResult(res);
|
||||
return res;
|
||||
|
Loading…
x
Reference in New Issue
Block a user