Select returns data available read returns no data

Select returns data available read returns no data

Post by sheadl » Sun, 16 Feb 2003 00:12:58



Hello All,
I have a problem I hope someone here can answer. I have multiple
sockets that I am watching with select. I get an indication from
select that there is data to be read from a socket I am interested in.
When I go to retrieve that data, read returns 0 bytes. When is it
possible that select can return that there is data available from a
particular socket but read dosen't have data available for that
socket? My OS is AIX.
 
 
 

Select returns data available read returns no data

Post by Chuck Dillo » Sun, 16 Feb 2003 01:22:30



> When is it
> possible that select can return that there is data available from a
> particular socket but read dosen't have data available for that
> socket? My OS is AIX.

http://www.faqs.org/faqs/unix-faq/socket/ item 2.13

-- ced

--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.

 
 
 

Select returns data available read returns no data

Post by Fletcher Glen » Thu, 20 Feb 2003 02:02:30



> Hello All,
> I have a problem I hope someone here can answer. I have multiple
> sockets that I am watching with select. I get an indication from
> select that there is data to be read from a socket I am interested in.
> When I go to retrieve that data, read returns 0 bytes. When is it
> possible that select can return that there is data available from a
> particular socket but read dosen't have data available for that
> socket? My OS is AIX.

What you describe constitutes an EOF condition on the selected socket.

--
                Fletcher Glenn

 
 
 

1. When do read() return 0 despite that select() returned 1

I have a somewhat unstable program that causes strange crashes.
The code is multi-threaded using sproc(). Sometimes one of the
threads starts to loop calling a select() with a filedescriptor
of a readble pipe, gets an indication of readability, does a
read() call wich returns 0, and so on.

do {
   noOfRead = select(...);
   if (noOfRead==1) {
     howMany = read(...);
     if (howMany > 0) {
        // Do something useful
     } else if (howMany==-1) {
       // Error output
       abort();
     }
   }

I am not asking about why the program crashes. I am just
curious why select() indicates bytes to be read, but read()
indicates no bytes and returns 0. If I can solve that, this
part of the code can do a graceful exit. As it is today,
this part of the codes get a lot of interest from people
trying to locate the cause of error, since it loops.
I would like a way to stop looping and produce a correct
diagnostic message. Today I get contradicting messages:
select says "go ahead and read" and read() says "nothing to read".

2. 2.4.19-rc1 sending SIGALRM to exec'd process

3. Select() returning 0 even though data on socket

4. Configuring X on Acernote light.

5. 2.5.62: /proc/ide/via reads return incomplete data, Bug #374

6. minimum good 386 for unix

7. dos emulator & security key

8. Socket problem: select() not returning when a new connection is available

9. (?) CGI script not always returning data

10. unamex Returns Binary Form of uname Data?

11. 2.5.62: /proc/ide/aec62xx returns incomplete data [1/17]

12. 2.5.62: /proc/ide/amd74xx returns incomplete data [3/17]