[Interest] QTSPCosket signal disconnected()

Igor Mironchik imironchick at gmail.com
Tue Aug 21 10:04:14 CEST 2012


I'm playint with this issue. And notice that the problem is not played 
too often.
Sometimes slotDisconnected() not invoked in general. What is problem too.
But when he invoked I have stable dead-lock. What is the reason? App is 
one-threaded.

> Hello.
>
> In the attachement you can find test applications. All applications 
> (server and client) are one-thread apps.
>
> But something going stange in the server. I specially added QMutex to 
> ServerSocket and when
> client disconnected from server application catches deadlock. How it's 
> possible? May be it's a bug in Qt?
>
> It's simple to reproduce: just run server then client and then stop 
> client...
>
> Look at the code:
>
> //
> // ServerSocketPrivate
> //
>
> struct ServerSocket::ServerSocketPrivate {
>     QMutex m_mutex;
>     QList< ClientSocket* > m_clients;
> };
>
>
> //
> // ServerSocket
> //
>
> ServerSocket::ServerSocket( QObject * parent )
>     :    QTcpServer( parent )
>     ,    d( new ServerSocketPrivate )
> {
> }
>
> ServerSocket::~ServerSocket()
> {
> }
>
> void
> ServerSocket::incomingConnection( int socketDescriptor )
> {
>     ClientSocket * socket = new ClientSocket( this );
>
>     if( socket->setSocketDescriptor( socketDescriptor ) )
>     {
>         connect( socket, SIGNAL( disconnected() ),
>             this, SLOT( slotDisconnected() ) );
>
>         {
>             MutexLocker lock( &d->m_mutex );
>
>             d->m_clients.append( socket );
>         }
>     }
>     else
>         delete socket;
> }
>
> void
> ServerSocket::slotDisconnected()
> {
>     qDebug() << "slotDisconnected()";
>
>     MutexLocker lock( &d->m_mutex );
>
>     sender()->deleteLater();
> }
>
> void
> ServerSocket::doThis()
> {
>     qDebug() << "doThis()";
>
>     MutexLocker lock( &d->m_mutex );
>
>     foreach( ClientSocket * socket, d->m_clients )
>         socket->sendData();
> }




More information about the Interest mailing list