Re: (Simple) problem with sockets

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

 




lawson_whitney@juno.com wrote:

> > 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,

Are you quite sure about that? I'm quite sure that accept() exhibits
the same behaviour as open(), dup() etc, i.e. it always returns the
lowest-numbered unused descriptor. I'm not aware of any system call
which allocates descriptors but doesn't behave this way.

> 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.

Unnecessary; a descriptor is an "int", but that doesn't mean it can be
*any* int. IIRC, you won't see a value >= 1024 unless you've modified
your kernel source.

> 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,

Er, are you under the impression that file descriptors are *arbitrary*
integers? They aren't; they are "small", non-negative integers
("small" meaning that you can reasonably use them as an array index).

> and what you get is an "OS" like win31 or win9x. Hash them instead.

Quite the opposite; Unlike Unix, Windows *does* use arbitrary integer
"handles" for this type of thing (one of the many reasons why WinSock
only superficially resembles BSD sockets).

> > 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.

No; it just means that the /proc/<pid>/fd "symlinks" which refer to
sockets aren't valid, in that "socket:[XXXX]" isn't a valid filename.

-- 
Glynn Clements <glynn.clements@virgin.net>
-
: 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