I have a question on how to reclaim used socket fd's or possibly it is how
to correctly close socket fd's so that they become available to the system
I am running a server and client programs on Intel based PCs running RH
Linux 6.1 (and couple 6.2)
I eventually run out of socket file descriptors on my server program at
about fd = 64, even though I have only a few sockets open on my server at
that time. I believe I am correctly closing sockets when I am done with
them (which I assume means that the resource would be given back to the
My server program has several socket file descriptors open at once ( I use
select() to see if any are available for reading, or if there is a new
connection waiting on the listen socket), and occasionally the clients will
go away for what ever reason, and also new clients can join at any time. If
a client dies or goes away, either explicitly (read() =0) or due to long
periods of inactivity(I have a tunable keep alive function), the server
calls shutdown(2) on that socket fd. The argument 2 to shutdown being that
neither sending or receiving is allowed. The reason for using shutdown()
rather than close() was either based on something I read in the Stevens book
or one of the Unix socket FAQ's, don't remember which, having to do with
close only referring to the current thread and shutdown means that everyone
is done with the fd (although my app is a single thread so theoretically
either should work)
If a new client attempts to connect, the socket call returns a new file
descriptor which is always incrementing. So as clients leave, and new
clients appear, the socket numbers increase until 64 at which time I get an
error which is something like "invalid file descriptor".
I know there is a way to increase the resources available system wide,
although I cant seem to find that reference, so feel free to remind me what
the command/syntax to increase resources is. But even that is a stop gap
measure, since eventually I will run out of socket file descriptors again.
Based on what I need to do, spawning new processes like an http server, will
not work for me. The only other solution that I could think of would be to
go to UDP exclusively and that way only one socket would be needed.
Although I would much prefer to figure out a way to make the operating
system recycle the no longer used socket file descriptors.
Any thought, or suggestions would be appreciated.
reply to newsgroup and/or reply to my hotmail address tigerman67