Good day, all in the list!
Some problems during detection "connection lost" via KeepAlive and
disconnect signal.
After enabling KeepAlive, if there is some data in the socket buffer,
disconnect signal is not working. So there is no way to detect cable lost.
After disconnecting, socket don't send disconnect signal, don't send
stateChanged signal, don't send error code.
bytesToWrite() returns 0 bytes.
If there is no data in the socket disconnected signal is working normal.
Here is the test code.
SocketTransport::SocketTransport(QObject *parent) : QObject(parent)
{
QObject::connect(&mSocket, &QTcpSocket::disconnected, this,
&SocketTransport::onDisconnect);
QObject::connect(&mSocket, &QTcpSocket::readyRead, this,
&SocketTransport::readData);
QObject::connect(&mSocket, &QTcpSocket::connected, this,
&SocketTransport::onConnected);
QObject::connect(&mTimer, &QTimer::timeout, this,
&SocketTransport::writeData, Qt::QueuedConnection);
}
void SocketTransport::establishConnection()
{
mSocket.connectToHost("192.168.1.2", 3333);
}
void SocketTransport::onDisconnect()
{
qDebug()<<"On disconnect";
}
void SocketTransport::readData()
{
}
void SocketTransport::onConnected()
{
qDebug()<<"OnConnected";
mSocket.setSocketOption(QAbstractSocket::KeepAliveOption, 1);
int Idle=1;
int Count=2;
int Interval=1;
if(setsockopt(static_cast<int>(mSocket.socketDescriptor()),
IPPROTO_TCP, TCP_KEEPIDLE,
&Idle, sizeof(Idle))<0)
qDebug()<<"Error setsockopt IPPROTO_TCP, TCP_KEEPIDLE";
if(setsockopt(static_cast<int>(mSocket.socketDescriptor()),IPPROTO_TCP,
TCP_KEEPCNT,
&Count, sizeof(Count))<0)
qDebug()<<"Error setsockopt IPPROTO_TCP, TCP_KEEPCNT";
if(setsockopt(static_cast<int>(mSocket.socketDescriptor()),
IPPROTO_TCP, TCP_KEEPINTVL,
&Interval, sizeof(Interval))<0)
qDebug()<<"Error setsockopt IPPROTO_TCP, TCP_KEEPINTVL";
mTimer.start(1000);
}
void SocketTransport::writeData()
{
qDebug()<<"BYTES to write"<<mSocket.bytesToWrite()<<mSocket.state();
if(mSocket.state()==QAbstractSocket::UnconnectedState)
{
qDebug()<<"Unconnected state";
QCoreApplication::processEvents();
return;
}
QUuid id=QUuid::createUuid();
QByteArray data=id.toByteArray();
qDebug()<<id<<data.size();
mSocket.write(data, data.size());
}
Can enybody help me with this problem?
Thank's a lot!!!
--
Oleg Shalnev (Kalpa Knowledge Integration Initiative)
----------------------------------------------
mailto: [email protected] , [email protected]
skype: oleg_shalnev
cell : +7 (918) 741 7217
Socket.tar.bz2
Description: BZip2 compressed data
_______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
