mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-28 01:04:41 +08:00
Fix disconnect problem on downloading
This commit is contained in:
parent
82079f43da
commit
c316734e8f
@ -39,6 +39,15 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
class PROFILER_API EasySocket
|
class PROFILER_API EasySocket
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
enum ConnectionState
|
||||||
|
{
|
||||||
|
CONNECTION_STATE_UNKNOWN,
|
||||||
|
CONNECTION_STATE_SUCCESS,
|
||||||
|
|
||||||
|
CONNECTION_STATE_DISCONNECTED
|
||||||
|
};
|
||||||
|
private:
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
typedef SOCKET socket_t;
|
typedef SOCKET socket_t;
|
||||||
#else
|
#else
|
||||||
@ -58,7 +67,7 @@ class PROFILER_API EasySocket
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
ConnectionState m_state = CONNECTION_STATE_UNKNOWN;
|
||||||
public:
|
public:
|
||||||
EasySocket();
|
EasySocket();
|
||||||
~EasySocket();
|
~EasySocket();
|
||||||
@ -71,6 +80,9 @@ public:
|
|||||||
|
|
||||||
bool setAddress(const char* serv, uint16_t port);
|
bool setAddress(const char* serv, uint16_t port);
|
||||||
int connect();
|
int connect();
|
||||||
|
|
||||||
|
void setState(ConnectionState state){m_state=state;}
|
||||||
|
ConnectionState state() const{return m_state;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EASY________SOCKET_________H
|
#endif // EASY________SOCKET_________H
|
||||||
|
@ -335,10 +335,16 @@ void EasyMainWindow::listen()
|
|||||||
int bytes = 0;
|
int bytes = 0;
|
||||||
|
|
||||||
static auto timeBegin = std::chrono::system_clock::now();
|
static auto timeBegin = std::chrono::system_clock::now();
|
||||||
while (true)
|
bool isListen = true;
|
||||||
|
while (isListen)
|
||||||
{
|
{
|
||||||
if ((bytes - seek) == 0){
|
if ((bytes - seek) == 0){
|
||||||
bytes = m_easySocket.receive(buffer, buffer_size);
|
bytes = m_easySocket.receive(buffer, buffer_size);
|
||||||
|
if(bytes == -1)
|
||||||
|
{
|
||||||
|
isListen = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
seek = 0;
|
seek = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +405,8 @@ void EasyMainWindow::listen()
|
|||||||
m_receivedProfileData.clear();
|
m_receivedProfileData.clear();
|
||||||
//loadFile(QString(tempfilename.c_str()));
|
//loadFile(QString(tempfilename.c_str()));
|
||||||
m_recFrames = false;
|
m_recFrames = false;
|
||||||
return;
|
isListen = false;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case profiler::net::MESSAGE_TYPE_REPLY_BLOCKS:
|
case profiler::net::MESSAGE_TYPE_REPLY_BLOCKS:
|
||||||
@ -424,6 +431,14 @@ void EasyMainWindow::listen()
|
|||||||
while (neededSize > 0)
|
while (neededSize > 0)
|
||||||
{
|
{
|
||||||
bytes = m_easySocket.receive(buffer, buffer_size);
|
bytes = m_easySocket.receive(buffer, buffer_size);
|
||||||
|
|
||||||
|
if(bytes == -1)
|
||||||
|
{
|
||||||
|
isListen = false;
|
||||||
|
neededSize = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
buf = &buffer[0];
|
buf = &buffer[0];
|
||||||
int toWrite = std::min(bytes, neededSize);
|
int toWrite = std::min(bytes, neededSize);
|
||||||
m_receivedProfileData.write(buf, toWrite);
|
m_receivedProfileData.write(buf, toWrite);
|
||||||
@ -446,6 +461,8 @@ void EasyMainWindow::listen()
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_easySocket.setState(EasySocket::CONNECTION_STATE_DISCONNECTED);
|
||||||
|
delete [] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpReceiverThread::run()
|
void TcpReceiverThread::run()
|
||||||
@ -623,6 +640,8 @@ void EasyMainWindow::onCollapseAllClicked(bool)
|
|||||||
|
|
||||||
void EasyMainWindow::onConnectClicked(bool)
|
void EasyMainWindow::onConnectClicked(bool)
|
||||||
{
|
{
|
||||||
|
if(m_isConnected)
|
||||||
|
return;
|
||||||
int res = m_easySocket.setAddress(m_hostString->text().toStdString().c_str(), m_portString->text().toUShort());
|
int res = m_easySocket.setAddress(m_hostString->text().toStdString().c_str(), m_portString->text().toUShort());
|
||||||
|
|
||||||
res = m_easySocket.connect();
|
res = m_easySocket.connect();
|
||||||
@ -721,6 +740,13 @@ void EasyMainWindow::onCaptureClicked(bool)
|
|||||||
|
|
||||||
m_downloading = false;
|
m_downloading = false;
|
||||||
|
|
||||||
|
if(m_easySocket.state() == EasySocket::CONNECTION_STATE_DISCONNECTED)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,"Warning" ,"Application was disconnected",QMessageBox::Close);
|
||||||
|
m_isConnected = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::string tempfilename = "test_rec.prof";
|
std::string tempfilename = "test_rec.prof";
|
||||||
loadFile(QString(tempfilename.c_str()));
|
loadFile(QString(tempfilename.c_str()));
|
||||||
/*m_isConnected = (m_server->state() == QTcpSocket::ConnectedState);
|
/*m_isConnected = (m_server->state() == QTcpSocket::ConnectedState);
|
||||||
|
@ -36,12 +36,6 @@ int EasySocket::bind(uint16_t portno)
|
|||||||
EasySocket::EasySocket()
|
EasySocket::EasySocket()
|
||||||
{
|
{
|
||||||
m_socket = socket(AF_INET, SOCK_STREAM, 0);
|
m_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
struct timeval tv;
|
|
||||||
|
|
||||||
tv.tv_sec = 1;
|
|
||||||
tv.tv_usec = 0;
|
|
||||||
|
|
||||||
//setsockopt(m_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EasySocket::~EasySocket()
|
EasySocket::~EasySocket()
|
||||||
@ -98,6 +92,14 @@ int EasySocket::connect()
|
|||||||
}
|
}
|
||||||
int res = ::connect(m_socket,(struct sockaddr *) &serv_addr,sizeof(serv_addr));
|
int res = ::connect(m_socket,(struct sockaddr *) &serv_addr,sizeof(serv_addr));
|
||||||
if(res == 0){
|
if(res == 0){
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
tv.tv_sec = 1;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
setsockopt(m_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval));
|
||||||
|
|
||||||
m_replySocket = m_socket;
|
m_replySocket = m_socket;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user