home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!bu.edu!cs!tasos
- From: tasos@cs.bu.edu (Anastasios Kotsikonas)
- Newsgroups: comp.unix.programmer
- Subject: Re: SO_REUSEADDR (was: Re: Socket Programm
- Message-ID: <101253@bu.edu>
- Date: 10 Nov 92 01:30:16 GMT
- References: <101017@bu.edu> <1992Nov9.161326.19246@wuecl.wustl.edu>
- Sender: news@bu.edu
- Organization: Computer Science Department, Boston University, Boston, MA, USA
- Lines: 66
-
- In article <1992Nov9.161326.19246@wuecl.wustl.edu> pete@arl.wustl.edu writes:
- >In article 101017@bu.edu, tasos@cs.bu.edu (Anastasios Kotsikonas) writes:
- >>In article <1992Nov7.023043.19007@wuecl.wustl.edu> pete@arl.wustl.edu writes:
- > [.. my comment saying SO_REUSEADDR doesn't work as advertised...]
- >>
- >>I am sorry but this is nonsense. I have used SO_REUSEADDR on BSD 4.1.1, AIX
- >
- >hmmm, I think some more detail is needed... I'm not saying your wrong
- >(please, no flames :-), just that I've got conflicting stories...
-
-
- ... technical stuff [which I do not understand] deleted ...
-
- Here is the code I am using that has NEVER had any problems:
-
- if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
- report_progress (report, "\ncreate_connection(): Could not create socket",
- TRUE);
- return -1;
- }
- if (setsockopt (sock, SOL_SOCKET, SO_SNDBUF, (char *) &sendbuf,
- sizeof (sendbuf)) < 0)
- report_progress (report, "\ncreate_connection(): Could not set socket \
- options", TRUE);
- if (setsockopt (sock, SOL_SOCKET, SO_RCVBUF, (char *) &recvbuf,
- sizeof (recvbuf)) < 0)
- report_progress (report, "\ncreate_connection(): Could not set socket \
- options", TRUE);
- if (setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
- sizeof (val)) < 0)
- report_progress (report, "\ncreate_connection():WARNING: Cannot toggle \
- keep-alive connections", TRUE);
- val = 1;
- if (setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
- sizeof (val)) < 0)
- report_progress (report, "\ncreate_connection():WARNING: Cannot toggle \
- reuse of local address", TRUE);
-
- ... and now for the binf() ...:
-
- while (bind (sock, (struct sockaddr *) &server, sizeof (server)) < 0 &&
- errno == EADDRINUSE && timeout < 180) { /* For perm port keep trying */
- ++timeout;
- errno = 0;
- sleep (1);
- }
- if (timeout >= 180) {
- report_progress (report, "\ncreate_connection(): Could not bind", TRUE);
- return -1;
- }
-
-
- TRUE, I expect bind to delay me, but it has never delayed more than 3 seconds
- (3 iterations of the loop).
-
- >I really just want an answer to how to close a socket hard, in such a way that any data
- >still in the system is discarded, and I can start up right away again. I realise that discarding
-
- I use close() which guarrantees the fastest return to the program, and flushing
- of the data if the connection is broken, etc.
-
- Lastly, I am very hesitant to believe that someone found a bug with
- SO_REUSEADDR after so many years in use! I would be convinced if I could read
- the code to inetd and in it such a problem was mentioned!!!
-
- Tasos
-