Re: Select(timeout) ?

Fons Rademakers (rdm@pcsalo.cern.ch)
Tue, 23 Mar 1999 00:59:21 +0100 (MET)


Hi Krzysztof,

you have to make the following fix in $ROOTSYS/src/NET_TMonitor.cxx:

Bool_t TTimeOutTimer::Notify()
{
fMonitor->SetReady((TSocket *)-1);
Remove(); // one shot only
return kTRUE;
}

add the "Remove()" line.

However, to get it to do what you want in your small test you have to make
the following change in serv.C:

{
TServerSocket *ss = new TServerSocket(9090,kTRUE);
TSocket *s=0;
//s = ss->Accept(); // <- will block always
TMonitor *m = new TMonitor();
m->Add(ss); // <- add server socket to monitor
...
...
}

Cheers, Fons.

> Dear ROOT users,
>
> I would like to use TMonitor::Select(timeout) method, but it
> seems as though I can't get it to do what I want.
> Below, I have included a short piece of code that illustrates
> my problem i.e. when I execute the m->Select(5000) the program
> stops there until new socket's activity is detected, and doesn't
> actually end the Select after the time-out. Why ?
>
> ROOT 2.20/06, Solaris 5.6
>
> Many thanks in advance for any comments.
>
> Best regards,
> Krzysztof
>
> ## Server #########################################################
> {
> TServerSocket *ss = new TServerSocket(9090,kTRUE);
> TSocket *s=0;
> s = ss->Accept();
> TMonitor *m = new TMonitor();
> m->Add(s);
>
> TSocket *ns=0;
> ns = m->Select(5000);
>
> if (ns == (TSocket*) -1) {
> printf("Time out.\n");
> } else {
> printf("Socket activity detected.\n");
> }
> }
> ## Client #########################################################
>
> {
> TSocket *s = new TSocket("localhost",9090);
>
> //The Server does not end Select until s->Send(..) is called.
> s->Send("HELLO");
> }
>
> _____________________________________________________________________
> Krzysztof Wiktor Zelazowski Email: Krzysztof.Zelazowski@cern.ch
> Etudiant technique div.EP |CERN| Tel.: +41 (22) 767 2382
> _____________________________________________________________________
>

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910