home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.protocols.tcp-ip      TCP and IP network protocols.      14,669 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 13,786 of 14,669   
   Barry Margolin to Pandurangan R S   
   Re: write(2) returning zero on a TCP soc   
   29 Jul 11 01:17:38   
   
   a7f01e67   
   From: barmar@alum.mit.edu   
      
   In article   
   <38bd2f79-5433-4674-832a-9c2d7f0a091b@x19g2000prc.googlegroups.com>,   
    Pandurangan R S  wrote:   
      
   > On Jul 27, 1:33 pm, Jorgen Grahn  wrote:   
   > > I got this question at work, and was a bit annoyed that I couldn't   
   > > easily find a straight answer in the man pages or in Stevens.   
   > >   
   > > Under what conditions could write(sock, buf, n), with n>0, return zero   
   > > for a TCP socket?  According to POSIX?  In Linux?   
   > >   
   > > The return values I'm comfortable with are:   
   > > n      - all got written   
   > > 1..n-1 - partial write   
   > > -1     - fatal error, EINTR or EWOULDBLOCK   
   > >   
   > > That doesn't seem to leave room for a distinct meaning of 0.   
   > >   
   > > This supposedly happened to the guy who asked me, on Linux. I'm not   
   > > sure if the socket was set blocking or nonblocking.   
   > >   
   > > /Jorgen   
   > >   
   > > --   
   > >   // Jorgen Grahn  > \X/     snipabacken.se>   O  o   .   
   >   
   > Return value of zero means nothing was written to the socket (socket   
   > send buffer is full, that it could not accommodate even a single   
   > byte). This is not a serious error, just that you should attempt again   
   > to write to the socket at a later point in time. In a sense, this is   
   > similar to partial write 1..n-1 bytes, but may be we cannot call this   
   > a partial write, since nothing was actually written. May be we should   
   > call it incomplete write in general instead of partial write if we   
   > want to be picky on the terms :)   
   >   
   > I believe the man page states this quite clearly   
   >   
   > "On success, the number of bytes written is returned (zero indicates   
   > nothing was written).  On error, -1 is returned, and errno  is  set   
   > appropriately."   
      
   How can this happen?   
      
   If the socket is in blocking mode and the buffer is full, the write   
   should block until it's able to write at least one byte, then return   
   1..n.   
      
   If the socket is in non-blocking mode and the buffer is full, it should   
   return -1 with errno = EWOULDBLOCK.   
      
   What other cases are there?   
      
   --   
   Barry Margolin   
   Arlington, MA   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca