[Qt-interest] QTcpServer in fortuneserver example

Jason H scorp1us at yahoo.com
Wed Feb 2 16:16:59 CET 2011


clientConnection is the key.

Each connected /instance/ is a connection pair. Therefore, your clientConnection 
instance of QTcpClient applies to that connection. This is identical to having 
multiple files open and calling file->write(...) In fact, they both inherit 
QIODevice.


There is no critical section.



________________________________
From: pmqt71 <pmqt71 at gmail.com>
To: qt-interest at trolltech.com
Sent: Wed, February 2, 2011 7:26:42 AM
Subject: [Qt-interest] QTcpServer in fortuneserver example


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?
 
thanks
pm


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110202/ddf17ab6/attachment.html 


More information about the Qt-interest-old mailing list