[Qt-interest] QTcpServer in fortuneserver example

Thiago Macieira thiago at kde.org
Wed Feb 2 16:08:29 CET 2011


Em quarta-feira, 2 de fevereiro de 2011, às 13:26:42, pmqt71 escreveu:
> Hi,
> the fortuneserver in qt 4.6.2 uses QTcpServer and accepts client connections
> without using threads :
> 
> 
>    tcpServer = new QTcpServer(this);
>    if (!tcpServer->listen()) {
>        ...
>    }
> 
>    ...
>    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));
>    ...
> 
>    void Server::sendFortune()
>    {
>        QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
>        ...
>        clientConnection->write(block);
>    }
> 
> 
> My question is: in this example, what QTcpServer does in case of concurrent
> client connections? Is it able to serialize them? The sendFortune method can
> access shared memory without protecting the critical section?

Well, there's no such thing as concurrent client connection. One happens 
before the other, even if just a few microseconds.

There's also no shared memory involved anywhere, nor any critical section.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110202/4cc4899a/attachment.bin 


More information about the Qt-interest-old mailing list