PDA

View Full Version : Multiple socket notifiers for same socket



bmn
17th August 2015, 11:58
Hello,

I am currently working an a server/client application using SSL/TCP.
In order do archive this, i do the following:

1. create a QTcpServer
2. make it listen to any host address and a specific port
3. connect the "newConnection()" SIGNAL to my "newTcpConnection()" SLOT
4. There i use the socketDescriptor of the nextPendingConnection and set it to a new sslSocket

The code looks like this:



void sslServer::newTcpConnection()
{
qDebug() << "New TCP connection";
qintptr descriptor = tcpServer->nextPendingConnection()->socketDescriptor();

QSslSocket *sslSocket = new QSslSocket(this);
if (!sslSocket->setSocketDescriptor(descriptor)) { //<--Displays mentioned error
qCritical() << "Setting socket descriptor failed";
emit error(sslSocket->errorString());
delete sslSocket;
return;
}
...
}


But i do not understand why I get the following warning:

"QSocketNotifier: Multiple socket notifiers for the same socket 520 and type Read"

The warning occurs when executing the marked line.
I do not use threads and i create a new socket for every new connection,
therefore it should only be one socket notifier per sslSocket.


I would appreciate any help.

Thank you!

anda_skoa
17th August 2015, 12:29
nextPendingConnection() is a convenience wrapper that results in a fully set up QTcpSocket.

For SSL, or any other special setup needs, the correct way is to derive from QTcpServer and overwrite incomingConnection().
That method gets the socket descriptor and allows you to set up a QSslSocket instead of a QTcpSocket.

Cheers,
_

bmn
17th August 2015, 13:06
Thank you so much!

I completely missed that, tryed it right now and works as you described :)