[Interest] QTSPCosket signal disconnected()

Igor Mironchik imironchick at gmail.com
Mon Aug 20 20:58:39 CEST 2012


Hello again.

I forgot to add that I use Qt 4.7.4 and MSVC 10.0

> 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