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,020 of 14,669   
   Barry Margolin to Jorgen Grahn   
   Re: shutdown(2) and TCP socket buffers   
   28 Aug 09 16:55:13   
   
   From: barmar@alum.mit.edu   
      
   In article ,   
    Jorgen Grahn  wrote:   
      
   > Partly to draw attention away from the recent irrelevant, off-topic   
   > heavily cross-posted trolling:   
   >   
   > What is the BSD socket call shutdown(fd, SHUT_RD) supposed to do to   
   > a TCP socket, really? I have a short program where I do   
      
   POSIX doesn't go into detail, and I don't think there's a concensus.   
      
   >   
   >     fd_ = socket(ai.ai_family, ai.ai_socktype, ai.ai_protocol);   
   >     if(fd_==-1) return false;   
   >   
   >     (void)setsockopt(fd_, SOL_SOCKET, SO_SNDBUF,   
   > 		     &bufsize_, sizeof bufsize_);   
   >   
   >     int rc = ::connect(fd_, ai.ai_addr, ai.ai_addrlen);   
   >     if(rc==-1) {   
   >         /* ... */   
   > 	return false;   
   >     }   
   >   
   >     rc = fcntl(fd_, F_SETFL, O_NONBLOCK);   
   >     assert(!rc);   
   >   
   >     rc = shutdown(fd_, SHUT_RD);   
   >     assert(!rc);   
   >   
   > but at least under Linux, the peer can happily write to me. 'netstat'   
   > shows my RX buffer growing and growing.  I assume it will fill up   
   > eventually, but that buffer is 64k or something like that.   
   >   
   > I haven't tried reading from the socket.  I assume I will not be   
   > awoken from select, nor be able to read anything.   
   >   
   > This isn't a /problem/ for me, just surprising. I would have expected   
   > my side to claim its TCP window is closed -- and maybe save several   
   > dozen kilobytes of buffer space per socket.   
      
   The common behaviors I thought were out there are:   
      
   1. Ack everything and just discard it.   
      
   2. Reject any data received with a RST.   
      
   I can't see why Linux is buffering the data if it's not going to let you   
   read it.  If it's buffering the data, my guess is that it's actually:   
      
   3. Ignore SHUT_RD.   
      
   --   
   Barry Margolin, barmar@alum.mit.edu   
   Arlington, MA   
   *** PLEASE don't copy me on replies, I'll read them in the group ***   
      
   --- 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