TSocket::Select returns -2

Hi.

The following call occasionally returns nerr = -2:

TSocket * send_socket = ....;
int timeout = -1; // for no timeout
nerr = send_socket->Select(TSocket::kWrite, timeout);

Where can I find out what this means?

Thanks

Hi Christos,

Starting out from the doc for TSocket::Select, looking at the source code and assuming you are on a Unix-like machine, I ended up in TUnixSystem::UnixSelect and (in the source code) I see that the ‘-2’ arises when the (Unix) system function ‘select’ gives a return value of -1 and the errno = EINTR.

Next step: I typed “unix pselect” into google, then I found the following website
http://www.opengroup.org/onlinepubs/000095399/functions/select.html
where it is written under the heading ERRORS :

Under the following conditions, pselect() and select() shall fail and set errno to:

[EINTR]
    The function was interrupted before any of the selected events occurred and before the timeout interval expired.

There ! I hope this helps, I’ve certainly learned something by doing it !!!
Cheers
John

Hi John.

wow… Ok, I didn’t expect it to be so complicated. :wink:

Thanks for the time you put into this. This is a very rare error that (when it occurs) results to my connection being completely frozen. It looks like my best option is to forcefully end the connection (and maybe try to re-connect), as there is no easy way of accessing the low-level information for further debugging…

Thanks again.

Hi,

in case of EINTR (i.e. -2) just call again Select(), you might want to do something like:

   while ((nerr = send_socket->Select(...)) == -2)
      ;

Cheers, Fons.

Hi Fons.

I followed your advice and I did something like this.

 while( (nerr = send_socket->Select(TSocket::kWrite, timeout)) == -2)
 {
   // stay here till we get something different than "-2";
   // this error means that the operation was interrupted before timeout
  cerr << " *** Error = " << nerr << " while waiting for socket << endl; 
  }

When I run into this problem I see the error just once

But then nothing happens. The connection seems to hang indefinitely.

There are also cases where the connection seems to hang, but I don’t get any error at all (i.e. I print out the error even if nerr != -2). Not sure if this is the same problem, but the result (frozen connection that is impossible to resurrect) is identical, so I thought I should mention it.

I am thinking of dropping the connection. Is there any additional info that could be useful? i.e. calling TSocket::IsValid(), or anything similar?

Using ROOT 5.12.00e.

Hi Christos,

how often does this happen? Do you have an example with a small client/server that shows this problem? In what case do you need a select on write? Normally you can send and it will block till the reader has read the data.

Cheers, Fons.

The code is not mine, but I know it doesn’t happen very often. I will see if I can get a small set of macros reproducing the problem.

[quote=“rdm”]In what case do you need a select on write? Normally you can send and it will block till the reader has read the data.
[/quote]

Well, there were two reasons for doing a TSocket::Select. First, to have the option of having a time-out mechanism in place if a socket is not responding within some reasonable time. Then, I had found attractive the idea of keeping statistics of how much time the client spends on waiting vs sending vs no-activity (idle).