<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-7">
<META content="MSHTML 6.00.2800.1126" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I noticed, that when a tcp server accepts a 
connection and finally the connection is closed, either when the client 
disconnects, or the server closes the connection, there remains a file 
descriptor open! Using lsof, or in /proc/(processID)/fd, I can see the file 
descriptor. At first I thought that the file descriptor whould be there, as long 
as the connection would be in TIME_WAIT state, but I was wrong.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Is this behaviour normal?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>If the server accepts connections at fast rates, 
then the result is Too many open files Errors...</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I only use one process to handle multiple client 
connections. I wanted to confirm it and used a very simple similar program 
and the result is the same...</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Here is the code I used to confirm 
it...</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Uses Sockets;</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Var<BR>     lSock : 
LongInt;<BR>     uSock : 
LongInt;<BR>     sAddr : TInetSockAddr;</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>     lLen  : 
LongInt;<BR>     sLine : String;</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>     SIn   : 
Text;<BR>     SOut  : Text;</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Procedure PError (Const S : 
String);</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Begin<BR>     Writeln 
(S, SocketError);<BR>     Halt (100);<BR>End;</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Begin<BR>     
lSock:=Socket (AF_Inet, Sock_Stream, PF_Unspec);<BR>     If 
SocketError<>0 Then PError ('Server : Socket : ');</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>     
sAddr.Family:=AF_Inet;<BR>     sAddr.Port  :=lo (3000) 
shl 8 or hi (3000);<BR>     sAddr.Addr  :=(1 shl 24) or 
127;</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>     If Not Bind 
(lSock, sAddr, SizeOf (sAddr)) Then PError ('Server : 
Bind');<BR>     If Not Listen (lSock, 1) Then PError 
('Server : Listen : ');</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>     
Repeat<BR>          Writeln 
('Accepting 
connection...');<BR>          lLen 
:=SizeOf (sAddr);<BR>          
uSock:=Accept (lSock, sAddr, 
lLen);<BR>          If 
SocketError<>0 Then PError ('Server : Accept : 
');<BR>          Writeln 
('Connection accepted...');</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New" 
size=2>          Sock2Text (USock, 
SIn, SOut);</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New" 
size=2>          Reset (SIn); 
<BR>          Rewrite (SOut); 
<BR>          While Not Eof (SIn) 
Do<BR>          
Begin<BR>               
ReadLn  (SIn, 
sLine); <BR>               write   
(sout,sline);<BR>               writeln 
(sline); <BR>          
End;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New" 
size=2>          Close 
(Sin);<BR>          Close 
(SOut);</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New" 
size=2>          ShutDown (uSock, 
2);<BR>     Until False;<BR>End.<BR></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>