|
|
|
@ -12,6 +12,8 @@ tcpClientRecv::tcpClientRecv(const QString uuid, QObject *parent /*= 0*/)
|
|
|
|
connect(socket_ptr_, SIGNAL(bytesWritten(qint64)), this, SLOT(on_bytes_written(qint64)), Qt::DirectConnection);
|
|
|
|
connect(socket_ptr_, SIGNAL(bytesWritten(qint64)), this, SLOT(on_bytes_written(qint64)), Qt::DirectConnection);
|
|
|
|
connect(socket_ptr_, SIGNAL(disconnected()), this, SLOT(on_disconnected()), Qt::DirectConnection);
|
|
|
|
connect(socket_ptr_, SIGNAL(disconnected()), this, SLOT(on_disconnected()), Qt::DirectConnection);
|
|
|
|
connect(socket_ptr_, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(on_socket_error(QAbstractSocket::SocketError)), Qt::DirectConnection);
|
|
|
|
connect(socket_ptr_, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(on_socket_error(QAbstractSocket::SocketError)), Qt::DirectConnection);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(sgStartSession(const QString, const QString&, qint16)), this, SLOT(on_session_start(const QString, const QString&, qint16)));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tcpClientRecv::~tcpClientRecv()
|
|
|
|
tcpClientRecv::~tcpClientRecv()
|
|
|
|
@ -54,8 +56,6 @@ void tcpClientRecv::set_msg_body(const QJsonObject& msg_body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tcpClientRecv::on_session_start(const QString uuid, const QString& ip_addr, qint16 port)
|
|
|
|
void tcpClientRecv::on_session_start(const QString uuid, const QString& ip_addr, qint16 port)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (uuid_ == uuid)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!connect_timeout_timer_)
|
|
|
|
if (!connect_timeout_timer_)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -71,7 +71,7 @@ void tcpClientRecv::on_session_start(const QString uuid, const QString& ip_addr,
|
|
|
|
trans_timeout_timer_->setInterval(2000);
|
|
|
|
trans_timeout_timer_->setInterval(2000);
|
|
|
|
connect(trans_timeout_timer_, SIGNAL(timeout()), this, SLOT(on_transfer_timeout()));
|
|
|
|
connect(trans_timeout_timer_, SIGNAL(timeout()), this, SLOT(on_transfer_timeout()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
if (uuid_ == uuid) {
|
|
|
|
if (connect_timeout_timer_)
|
|
|
|
if (connect_timeout_timer_)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
connect_timeout_timer_->stop();
|
|
|
|
connect_timeout_timer_->stop();
|
|
|
|
@ -80,7 +80,6 @@ void tcpClientRecv::on_session_start(const QString uuid, const QString& ip_addr,
|
|
|
|
begin(ip_addr, port);
|
|
|
|
begin(ip_addr, port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tcpClientRecv::on_connected()
|
|
|
|
void tcpClientRecv::on_connected()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -112,10 +111,14 @@ void tcpClientRecv::on_ready_read()
|
|
|
|
if (current_recv_size_ >= should_recv_size_)
|
|
|
|
if (current_recv_size_ >= should_recv_size_)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
char* dataPtr = pDataRecv_ + current_recv_size_;
|
|
|
|
char* dataPtr = pDataRecv_ + current_recv_size_;
|
|
|
|
|
|
|
|
if ((current_recv_size_ + size) > should_recv_size_)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
size = should_recv_size_ - current_recv_size_;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (dataPtr != nullptr)
|
|
|
|
if (dataPtr != nullptr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
memcpy(dataPtr, pDataRecvBuf, size);
|
|
|
|
|
|
|
|
current_recv_size_ += size;
|
|
|
|
current_recv_size_ += size;
|
|
|
|
|
|
|
|
memcpy(dataPtr, pDataRecvBuf, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (trans_timeout_timer_)
|
|
|
|
if (trans_timeout_timer_)
|
|
|
|
@ -214,3 +217,8 @@ Q_SLOT void tcpClientRecv::on_transfer_timeout()
|
|
|
|
|
|
|
|
|
|
|
|
close();
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
服务端主动断开时会出现崩溃 异常
|
|
|
|
|
|
|
|
服务端主动关闭时会崩溃
|
|
|
|
|
|
|
|
*/
|