bug-commoncpp
[Top][All Lists]
Advanced

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

SocketService problems


From: Barnaby Gray
Subject: SocketService problems
Date: Fri, 4 Jan 2002 20:20:35 +0000
User-agent: Mutt/1.3.25i

I spent some time investigating SocketService as I want to use it in
my project and found a couple of problems - I noticed after going
through the list archives a fix for one of them, but the fix is
incorrect too.

1. The poll in SocketService is inside the mutex - it should be
   outside the mutex, otherwise no other SocketPort's can add
   themselves when it is inside poll. The previous fix on the list
   suggested adding a getCount() method to the descriptor list and
   using that instead of count+1 as the second argument for poll. This
   is incorrect, as their suggested count is the size of memory
   allocated for the descriptor list, not the actual number of
   descriptors in the list (it could grow and then shrink when sockets
   are closed).

2. In SocketService::Attach it calls Start on the thread if the
   SocketPort linked list was empty and a Socket Port was
   added. Otherwise it calls Update to inform the Socket thread. This
   behaviour is wrong for the case when you close all Socket Port's
   and then add another SocketPort. It should only call Start once,
   and then always call Update's on successive Attach'es.

I've attached my patch to port.cpp. I solved problem 1 by using
lastcount (which == count + 1) and is safe to use outside the mutex as
it's local to the method. I solved problem 2 by taking out the
implicit Start on the thread. This is just my preferred behaviour, I
prefer to explicitly start the thread, so on Attach it always uses
Update. I guess you could keep it implicit easily by checking if the
thread is started and starting it if it isn't or calling update
otherwise.

Otherwise a damn good library - keep up the good work! :-)

Cheers,

Barnaby



reply via email to

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