bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Synchronization problem in TCPSocket <-> SocketPort interaction


From: Dimitar Dimitrov
Subject: Synchronization problem in TCPSocket <-> SocketPort interaction
Date: Tue, 25 Feb 2003 14:46:05 +0100
User-agent: KMail/1.5

Hi,

First to say that I downloaded Common C++ library just couple of days ago and 
may be I don't get everything right. I think I run into a problem which may 
turn out to be a result only of my misunderstanding.

I'll try to explain it step by step. It can be reproduced with 
SampleSocketPort example although not very easily.

The issue is the following:

1. TCPSocket class is not part of SocketPort hierarchy. No problem with that 
as far as we don't come to the fact that SocketService cannot handle directly 
a TCPSocket object. 

2. As a result of 1. if someone tries to create a DerivedFromSocketPort object 
(TCPSocket a parameter in the constructor of SocketPort) she has to do this 
in a thread different from the thread of the SocketService object. 
SampleSocketPort is a good example for this.

So far so good... 
But, during construction of our DerivedFromSocketPort object it attaches 
itself to the SocketService. If the constructor of DerivedFromSocketPort 
class is very heavy it can happen that the SocketService thread tries to 
delete our object before it is fully constructed, which will quite possible 
result in a crash...

An easy workaround is to provide a 0 to the constructor of SocketPort and to 
use attach at the end of DerivedFromSocketPort's constructor. 
Although this will not prevent some first-time users like me to spend half a 
day trying to figure out what is going on it solves the problem somehow.

I apologize for asking you to read that much till here ;-)  but I have one may 
be not that smart idea: Wouldn't it be good if SocketService can handle 
TCPSocket somehow? After all it is more than natural to include a listening 
socket in a select or poll...

Regards,
Dimitar


PS: Did I forget to say thank you guys for this library. I think it is really 
cool and I plan to spend some more time with it.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]