[Qt-interest] QTcpServer in fortuneserver example
pmqt71
pmqt71 at gmail.com
Wed Feb 2 18:26:35 CET 2011
I mean I could use a non local variable (say a member of class Server) in
the sendFortune without protecting it:
void Server::sendFortune()
{
//write to the client
clientConnection->write(m_Block);
//change m_Block
....
}
that because, as you confirm, the QTcpServer is not using threads, timers
etc. but it is serializing the client connections.
2011/2/2 Thiago Macieira <thiago at kde.org>
> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110202/130b94c3/attachment.html
More information about the Qt-interest-old
mailing list