[Qt-interest] Can two thread share a QAbstractSocket?

Gabriele Kahlout gabriele at mysimpatico.com
Wed May 12 19:02:24 CEST 2010


I start a thread from within QTcpServer::incomingConnection(int)

> and pass that thread the file number. Once within that threads run
> code I create the QTcpSocket object and ::setSocketDescriptor.
>
> Works like a charm.
>
>
I've been doing that with success too. However how do I achieve the same
behavior with udpsockets?

Also, since threads share the heap, why cannot they share it (by pointers)?


http://stackoverflow.com/questions/1665419/do-threads-share-the-heap


> Bill
>
>
> > public void run() {
> >  while (true) {
> >                 Socket clientSocket = listener.accept();
> >                 new ClientHandler(clientSocket);
> > }
> >
> > -----
> > ClientHandler
> >
> > public void run() {
> >  while (true) {
> >
> >             String msg = receive();
> > }
> >
> >
> http://code.google.com/p/javatcpchat/source/browse/trunk/src/server/ClientHandler.java
> >
> > 2010/5/12 Gabriele Kahlout <gabriele at mysimpatico.com
> > <mailto:gabriele at mysimpatico.com>>
> >
> >     interesting. Why not?
> >
> >     2010/5/12 Thiago Macieira <thiago at kde.org <mailto:thiago at kde.org>>
> >
> >         Em Quarta-feira 12 Maio 2010, às 17:50:04, Gabriele Kahlout
> >         escreveu:
> >          > Hello,
> >          >
> >          > I am trying to have a (udp/tcp) server to pass sockets
> >         (socketdescriptor)
> >          > to another thread, which communicates with the client and
> >         authenticates
> >          > it. I'm having several issues, so I was wondering if the
> >         above could be
> >          > one of them.
> >
> >         Answering the subject: no.
> >         --
> >         Thiago Macieira - thiago (AT) macieira.info
> >         <http://macieira.info> - thiago (AT) kde.org <http://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 trolltech.com <mailto:Qt-interest at trolltech.com>
> >         http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> >
> >
> >
> >     --
> >     Regards,
> >     K. Gabriele
> >
> >     --- unchanged since 25/1/10 ---
> >     P.S. Unless a notification (LON), please reply either with an answer
> >     OR with " ACK" appended to this subject within 48 hours. Otherwise,
> >     I might resend.
> >     In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧
> >     IsAnswerTo(x, this) ∨ (In(subject(this), subject(x)) ∧ In(ACK,
> >     subject(x)) ∧ ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this).
> >
> >     Also note that correspondence may be received only from specified a
> >     priori senders, or if the subject of this email ends with a code,
> >     eg. -LICHT01X, then also from senders whose reply contains it.
> >     ∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y.
> >     In(y, subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ).
> >
> >
> >
> >
> > --
> > Regards,
> > K. Gabriele
> >
> > --- unchanged since 25/1/10 ---
> > P.S. Unless a notification (LON), please reply either with an answer OR
> > with " ACK" appended to this subject within 48 hours. Otherwise, I might
> > resend.
> > In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ IsAnswerTo(x,
> > this) ∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧
> > ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this).
> >
> > Also note that correspondence may be received only from specified a
> > priori senders, or if the subject of this email ends with a code, eg.
> > -LICHT01X, then also from senders whose reply contains it.
> > ∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. In(y,
> > subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ).
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>



-- 
Regards,
K. Gabriele

--- unchanged since 25/1/10 ---
P.S. Unless a notification (LON), please reply either with an answer OR with
" ACK" appended to this subject within 48 hours. Otherwise, I might resend.
In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ IsAnswerTo(x, this)
∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧
¬IsAnswerTo(x,this)) ⇒ ¬IResend(this).

Also note that correspondence may be received only from specified a priori
senders, or if the subject of this email ends with a code, eg. -LICHT01X,
then also from senders whose reply contains it.
∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. In(y,
subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100512/76d9b19a/attachment.html 


More information about the Qt-interest-old mailing list