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