[Qt-interest] sockets and threads on linux
william.crocker at analog.com
william.crocker at analog.com
Tue Feb 15 15:05:49 CET 2011
>
> p.s. Bill, as I experienced, your steps 2 and 3 make the socket live in
> the main thread rather than in the one you create. I used moveToThread
> to correctly move the QTcpSocket object to the dedicated thread. See my
> previous messages where Thiago gave me the right suggestions.
>
No. My step #3 makes the QTcpSocket live in the service thread as it is
created as an automatic variable of the ::run function which is
*in the thread*. Don't be confused by the int file descriptor which starts
in the main thread and is passed down to the service thread. Integer file
descriptors are process-global. The main thread hands the fd off to the
service thread and never touches it again.
>
>
>
> 2011/2/15 william.crocker at analog.com <mailto:william.crocker at analog.com>
> <william.crocker at analog.com <mailto:william.crocker at analog.com>>
>
> Some detail omitted :-)
>
> 1 - Subclass QTcpServer and redefine incomingConnection(int)
> ( The QTcpServer runs in the main thread. )
>
> 2 - In this function, create a thread and pass it the int file
> descriptor.
>
> 3 - In the ::run method of the thread, create a ::run/local
> QTcpSocket and
> setSocketDescriptor with the incoming file desc.
>
> 4 - Create some other ::run/local object to handle the readyRead()
>
> 5 - Create and ::exec an event loop.
>
> I have a server which has been running flawlessly
> under this scenario for years.
>
> Bill
>
> > On Monday, 14 de February de 2011 19:43:34 Francisco Gonzalez wrote:
> >> In your implementation details both signal readyRead() and slot
> >> onReadyRead() are members of your MyTcpSocket class, so when
> you move the
> >> pSocket object to the QThread th, you are moving both the
> signal, and the
> >> processing function. I do not understand how can it improve the
> socket
> >> capability of processing, as both functions live in the same thread.
> >
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com <mailto:Qt-interest at qt.nokia.com>
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
More information about the Qt-interest-old
mailing list