Using TMonitor with signal/slot mechanism

Hello,

I have been studiing the TSocket and TMonitor classes lately. Especially I investigated the /tutorials/spy.c and /tutorials/spyserv.c examples.

Now I am wondering, wouldn’t it be more convenient to use a signal instead of polling with TMonitor::Select(Long_t timeout) for a new socket event in spyserv.c? Something like TMonitor::NewSocketEvent(TSocket * sock)?

Then one could do this (in spyserv.c)

Just an idea. Maybe this cannot work for some reason I am not aware of.

Cheers,

Lutz

Hi Lutz,
the best way to promote an idea is
to send the code (a patch ).
Anyway idea sounds reasonable :smiley:

Regards. Valeriy

Hi Valeriy,

I don’t know wether the coding I did will actually work.
As far as I understand it, the TSocketHandler will be notified with a signal as soon as there is something on the socket. It will then call TMonitor::SetReady(TSocket *sock). Thats why I added the new signal call to this TMonitor function.

Attached are the modified TMonitor.h and TMonitor.cxx files. The following changes are made:
in TMonitor. h the following line is added:

void NewSocketEvent(TSocket * sock) {Emit("NewSocketEvent(TSocket*)", (Long_t)sock)}; // *SIGNAL*
in TMonitor.cxx the SetReady function is changed to the following:

[code]//______________________________________________________________________________
void TMonitor::SetReady(TSocket *sock)
{
// Called by TSocketHandler::Notify() to signal which socket is ready
// to be read. User should not call this routine. The ready socket will
// be returned via the Select() user function.

fReady = sock;
NewSocketEvent(sock);
}[/code]

Will this work? Unfortunatly I am only using the precompiled binaries of root, so I can’t test it myself.

Cheers,

Lutz

Hi Lutz,
here is CVS log:

Regards. Valeriy