Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pacbell!rtech!wrs!hwajin From: hwajin@wrs.wrs.com (Hwajin Bae) Newsgroups: comp.protocols.tcp-ip Subject: Re: TCP/IP close connection TIME_WAIT ? Keywords: tcp Message-ID: <749@wrs.wrs.com> Date: 23 Aug 89 17:15:00 GMT References: <227@melpar.UUCP> Reply-To: hwajin@wrs.wrs.com (Hwajin Bae) Distribution: usa Organization: Wind River Systems, Emeryville, CA Lines: 65 In article <227@melpar.UUCP> toppin@melpar.UUCP (Doug Toppin) writes: >We are using IBM Xenix 2 on the PC/AT with Network Research Corp >implementation of TCP/IP (called Fusion) and have hit a snag. >We often get the error EWOULDBLOCK on a heavily used socket (many >opens and closes). In the Sept. MIPS magazine David Betz writes: >"after a close, the resources used by that connection are not freed >immediately... Since this time interval is in the tens of seconds, >eventually all the resources are tied up in this TIME_WAIT." >My questions are: >* is the time value a constant? TCP Protocol Specification (RFC 793) defines 2*MSL (Maximum Segment Lifetime) to be the time-out value for the TIME_WAIT state to reach the CLOSED state. TCB is not deleted until this time-out happens. BSD 4.3-tahoe TCP/IP uses MSL of 30 seconds. >* is it tunable? If you have the source, yes. If you have an operating system that let's you change operating system parameters on the fly, yes. >* is the value part of the TCP/IP specification? In RFC 793, MSL is defined to be 2 minutes -- the value seems to be arbitrary. >* is it possible to detect that you are using the last available resource? If you have netstat program, you can to "netstat -a" to see a list of PCB's. Count the TCP PCB's and subtract the number of the TCP PCB's from the maximum number of sockets configured into your kernel. >* is it possible to allocate more of these resources? You should be able to tune the kernel by using kernel configuration package. Each Unix system has its own different kernel tuning mechanism. You will need to read the documentation on your system to figure out how to re-build your kernel. Mostly on system V dervied Unix OS's use "conf.c" and "config.h" files that are created by "config" program using the database files "master" and "dfile". One thing that you can try to get around this TIME_WAIT state in TCP implemenations is to set the SO_LINGER option on your SOCK_STREAM socket with the linger time out value of 0. When you close the socket that has the SO_LINGER option on and the linger time is zero, 4.3 BSD based TCP/IP will close the connection immediately. In 4.2 BSD based TCP implementations SO_DONGLINGER option can be used. #include ..... #ifdef BSD_43 struct linger linger; linger.l_onoff = 1; linger.l_linger = 0; setsockopt (sock, SOL_SOCKET, SO_LINGER, &linger, sizeof (linger)); #else int on = 1; setsockopt (sock, SOL_SOCKET, SO_DONTLINGER, &on, sizeof (on)); #endif /* BSD_43 */ -- Hwajin Bae (hwajin@wrs.com) Wind River Systems 1351 Ocean Ave. Emeryville, CA 94608 USA Tel: 415/428-2623 Fax: 415/428-0540