home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / question / 9549 < prev    next >
Encoding:
Internet Message Format  |  1992-07-29  |  1.7 KB

  1. Path: sparky!uunet!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: unbinding a port
  5. Date: 29 Jul 1992 21:37:03 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 27
  8. Message-ID: <15731vINNl7e@early-bird.think.com>
  9. References: <1992Jul16.131221.16529@odin.diku.dk>
  10. NNTP-Posting-Host: telecaster.think.com
  11.  
  12. In article <1992Jul16.131221.16529@odin.diku.dk> robert@diku.dk (Robert Martin-Legene) writes:
  13. >When you set up a program to run on a certain port, with socket,
  14. >setsockopt, bind & listen, it's ready to connect to. But how do you
  15. >make your server refuse connection to the port again (_without_
  16. >shutting down your program)?
  17.  
  18. Strange, someone else asked a very similar question yesterday, but possibly
  19. in another group (comp.unix.programmer, I think), although historically it
  20. doesn't seem to be a FAQ.
  21.  
  22. In any case, the answer is to close the listening socket.  This won't
  23. affect the connected sockets that were derived from it.
  24.  
  25. One problem: if any connection requests come in before you close it,
  26. they'll be accepted, but you won't be able to call accept(2) to get them.
  27. I don't know offhand what the system will do with those pending connections
  28. (it should probably send either a FIN or RST, but I haven't tried it).  You
  29. might be able to prevent this by specifying a backlog of 0 in the listen(2)
  30. call (I'm guessing that "pending connections" doesn't include connections
  31. that come in while you're blocked in accept(2)).  If this doesn't work, you
  32. could make the window small by specifying a backlog of 1 and call close(2)
  33. as soon as accept(2) returns.
  34. -- 
  35. Barry Margolin
  36. System Manager, Thinking Machines Corp.
  37.  
  38. barmar@think.com          {uunet,harvard}!think!barmar
  39.