Select return ok, but nothing to read ??

Select return ok, but nothing to read ??

Post by Gautier Fabric » Fri, 16 Jun 2000 04:00:00



Hi,

I have a pragram that create a channel between two sockets (kind of proxy).
Everything i read from one socket is writen to the other.

I use select to see if there is something to read on either one or the
other socket.

The main loop looks like this:

         while(1){      
                FD_ZERO(fds);
                FD_SET(socket_to,fds);
                FD_SET(socket_client,fds);
                select(socket_client+1,fds,NULL,NULL,NULL);
                if(FD_ISSET(socket_client,fds)){
                        r=recv(socket_client,buf,BUFSZ,0);
                        send(socket_to,buf,r,0);
                        }
                if(FD_ISSET(socket_to,fds)){
                        r=recv(socket_to,buf,BUFSZ,0);
                        send(socket_client,buf,r,0);
                        }
                }

When i made my test using an http server on one side and a telnet
client on the other side. I tested sending an http get command, all
goes well but after the the server reply is done, the select always
return 1 saying there is something to be read from the socket_to (http
serveur) but the recv call always return 0.

I can't understand were is my fault. (this should be my fault but i
can't understand that the select says there is something to be read,
and that when reading there is nothing... and its keep looping)

Thanks

A+
--
Fabrice Gautier

 
 
 

Select return ok, but nothing to read ??

Post by Barry Margoli » Fri, 16 Jun 2000 04:00:00




Quote:>When i made my test using an http server on one side and a telnet
>client on the other side. I tested sending an http get command, all
>goes well but after the the server reply is done, the select always
>return 1 saying there is something to be read from the socket_to (http
>serveur) but the recv call always return 0.

read() or recv() returning 0 indicates EOF, i.e. the other end closed the
connection after it finished sending the data.  Why do you think this is
wrong?

Quote:>I can't understand were is my fault. (this should be my fault but i
>can't understand that the select says there is something to be read,
>and that when reading there is nothing... and its keep looping)

Select isn't saying there's something to be read.  It's saying that
read/recv won't block.  And it doesn't -- it returns 0 immediately, doesn't
it?

--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. select return OK, but read EAGAIN

hi

   My server is using select to manage the incomming connections, when
select return OK, read return -1 with errno set to EAGAIN (of course I've
checked the readability using FD_ISSET), even there is only one connection.
   I am wondering if this is because the client is keep sending lots of data
when server is reading. Since the client is writing out 1M bytes of data in
one large buffer.

Loren

2. pmud leaves display on

3. Select returns data available read returns no data

4. source

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

6. wyse 50 term emulation for connecting win95 pc's to unix server via serial?

7. Q: select(S) finds, FD_*is*SET, but nothing to read

8. Kernel 2.2.2 and NNTP performance

9. Does select return "read ready" or "won't block" status?

10. select(read) on an empty file returns 1

11. read() after successful select() returns 0 !!!

12. Does select() return if the FD changed before select() was called?

13. DIP connects OK but nothing works!