why would a socket read() set errno to EWOULDBLOCK but still read?

Jim Bride bridej at sequent.com
Sat Jun 29 03:40:32 AEST 1991


mlevin at jade.tufts.edu writes:


>   I am doing a read() on a connected TCP socket (BSD 4.3) marked as
>non-blocking. For some reason, the read returns the proper number of
>characters read (or sometimes 0), but sets errno to EWOULDBLOCK. Why
>is this? My program never did this before; I was under the impression
>that if no data was available, it should return -1. Is this a possible
>event, or am I trashing memory somewhere? Please reply to
>mlevin at jade.tufts.edu. 

According to the man page, when you set the descriptor for the socket as
non-blocking (ie with the FNDELAY flag to fcntl()), the read will return
EWOULDBLOCK to let you know that the operation would have blocked had under
normal circumstances.  You read definitely should be returning -1 (at least
this is how it works under Dynix and SunOS.)   It sounds like there might be
a bug in read() on your machine.  I'd be interested to find out what was
causing your problem.
 
>Mike Levin

- Jim Bride	bridej at sequent.com	
----------------------------------------------------------------------------



More information about the Comp.unix.programmer mailing list