tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: readv() on TCP socket returns 0

> readv() returns 0 on EOF.  If the file descriptor is a TCP socket, I
> guess that means the connexion was closed,

Not necessarily.  shutdown(...,SHUT_WR) (or the local equivalent) on
the sending end can produce this without closing the connection
entirely.  (Unless you think of a TCP socket as being two connections,
one in each direction, in which case yes, it means the connection
you're reading from was closed.)

> but are there other situations where readv() can return 0 for a TCP
> socket?

I think dyoung is mostly correct: the only case where a 0 return for
readv on a TCP socket isn't a bug, except for the "write data flow
closed" case, is the case where the sum of the iov_len values is zero.
(dyoung said where iovcnt is zero, but, as I read the code, a nonzero
iovcnt but zero in all iov_len values will have identical effect.)

If you care about portability, I would recommend not counting on this.
For example, it wouldn't surprise me if some other OSes returned zero
for a nonblocking read with no data immediately available.  (I don't
know of any specific examples.)

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML      
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index