Re: (Simple) problem with sockets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Sun, 22 Apr 2001, Lee Chin wrote:

> This is more of a Linux socket API question... I have a server thread that
> accepts (accept sys call) socket connections and then services a client
> request and closes the socket connection using:
>
> shutdown(fd, SHUT_RDWR);
> close(fd);
>
> My problem is this... after a while I see that the file descriptor returned
> by the accept system call slowly starts increasing.  It starts increasing in
> the integer file descriptor number returned by the system call (the FD that
> we use to do the read and write system calls).
>
> I have two problems:
> 1) I'm using the file descriptor as an index into a fixed size array

Don't.  You don't control the value of the fd, so it is unwise to use it
as an index unless your array can have as many entries as the type of
the index can have values.  That is a lot of core to hold not much
content, and even if it is only virtual. it has to be mapped to
somewhere.  If they have to cater for programmers like you, programmers
like you give OS programmers hives, and what you get is an "OS" like
win31 or win9x.  Hash them instead.

> 2) I'm scared of eventually running out of file descriptors.

I don't think you will.  When it gets around to them, I think the system
will reuse the old numbers, but I can't see an easy way to force it to.
>
> Further more, when I do a "file /proc/PID/fd/XXX" I get a "/proc/PID/fd/XXX:
> broken symbolic link to socket:[BLAH]"
>
You'll have to be a bit more specific what you mean by XXX before I can
answer that.  Maybe not.  broken symbolic link means socket:[BLAH] is
gone.  Doesn't exist.  You closed it, you don't love it anymore, it has
walked out on you.  GONE.

> Why is this file descriptor still lingering around and how do I get rid of
> it when I do a close on the socket?

It isn't.  Just hash the damned fd's.
>
> Thanks
> Lee

Lawson

If you don't want my peaches, then don't shake my tree.
---cut here


________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/tagj.
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux