"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
From your description it looks like you are opening server socket for each accept(2) That is not necessary. Create server socket once bind(2) it listen(2) then call accept(2) on it in a loop (or better yet - give it to poll(2) ) Edit 0: By the way shutdown(2) on listening socket is totally meaningless, it's intended for connected sockets only.
From your description it looks like you are opening server socket for each accept(2). That is not necessary. Create server socket once, bind(2) it, listen(2), then call accept(2) on it in a loop (or better yet - give it to poll(2)) Edit 0: By the way, shutdown(2) on listening socket is totally meaningless, it's intended for connected sockets only.
Correct, I am opening the server socket for each accept. However it is not possible to reorganize my program this way, I need to maintain a strict 1:1 coupling between ports and servers. Besides, this doesn't explain why the fd is failing to be freed.
– Nigel Aug 5 '09 at 19:09 1 Are you binding that server socket to different port every time? – Nikolai N Fetissov Aug 5 '09 at 19:30.
From the socket manpage: SO_REUSEADDR Indicates that the rules used in validating addresses supplied in a bind(2) call should allow reuse of local addresses. For PF_INET sockets this means that a socket may bind, except when there is an active listening socket bound to the address. When the listening socket is bound to INADDR_ANY with a specific port then it is not possible to bind to this port for any local address.
Yes I am using "SO_REUSEADDR" : int yes = 1; setsockopt(server_SD,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)); – Nigel Aug 5 '09 at 11:02.
If so, your children may be inheriting the opened file descriptors. If this is the case, you should have the child close any fds that don't belong to it.
No, not using fork. My client processes are spawned using a system call, and are not inheriting anything from the server/parent. – Nigel Aug 5 '09 at 11:17.
This looks like you might have a "TIME_WAIT" problem. IIRC, TIME_WAIT is one of the status a TCP socket can be in, and it's entered when both side have closed the connection, but the system keeps the socket for a while, to avoid delayed messages to be accepted as proper payload for subsequent connections. You shoud maybe have a look at this (bottom of page 99 and top of 100).
And maybe that other question.
1 I have used : setsockopt(server_SD, SOL_SOCKET, SO_LINGER, &l, sizeof (l)); with l set to 0. So no, the socket should not linger. Also, a look at netstat tells me that the connections are going away quickly, but 'ls /proc//fd' tells me that the file descriptors are not being released.
– Nigel Aug 5 '09 at 11:45 1 TIME_WAIT sockets should not consume file descriptors if they have been closed by the process(es) which own them. – MarkR Aug 5 '09 at 11:47 Use SO_REUSEADDR instead of SO_LINGER unless you understand exactly what both options do. – Kristof Provost Aug 5 '09 at 13:50 I Believe I do, Are you saying they should not be used concurrently?
– Nigel Aug 5 '09 at 14:16.
One needs to close the client before closing the server (reverse order to my code above! ) Thanks all who offered suggestions!
Run your program under valgrind with the --track-fds=yes option: valgrind --track-fds=yes myserver You may also need --trace-children=yes if your program uses a wrapper or it puts itself in the background. If it doesn't exit on its own, interrupt it or kill the process with "kill pid" (not -9) after it accumulates some leaked file descriptors. On exit, valgrind will show the file descriptors that are still open and the stack trace corresponding to where they were created.
Running your program under strace to log all system calls may also be helpful. Another helpful command is /usr/sbin/lsof -p pid to display all currently used file descriptors and what they are being used for.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.