tml at iki.fi
Tue May 2 03:49:26 PDT 2006
> Tor Lillqvist schrieb:
> > I once had a test program to check this but can't find it
> > right now, but IIRC you didn't even have to try very hard to get
> > overlap (no need to open a stupendous amount of files or sockets).
Ralf Habacker writes:
> How do you have performed the test if you don't open sockets or files ?
Uh, did I say I did? My test program did what yours does, more or
less, except that it explicitly looked for overlaps and didn't bother
outputting much else.
> The following test program shows me that on Windows XP socket and file
> descriptors are unique.
Please note that to prove something doesn't happen a quite strong
proof is needed. On the other hand, to disprove it, just one
counter-example is needed...
> listen_fd=1784 file_fd=3 listen_handle=-1 file_handle=1776
> listen_fd=996 file_fd=101 listen_handle=-1 file_handle=992
> listen_fd=988 file_fd=102 listen_handle=-1 file_handle=984
Ah, but you conveniently run only 100 loops in your program. As you
should have noticed the socket number keeps decreasing. If you would
have run the loop longer, you would have seen overlap... When I change
the 100 to 1000, the interesting parts of the output are:
listen_fd=232 file_fd=212 listen_handle=-1 file_handle=228
listen_fd=224 file_fd=213 listen_handle=-1 file_handle=220
listen_fd=216 file_fd=214 listen_handle=-1 file_handle=212
listen_fd=208 file_fd=215 listen_handle=260 file_handle=204
listen_fd=200 file_fd=216 listen_handle=324 file_handle=196
listen_fd=192 file_fd=217 listen_handle=388 file_handle=188
listen_fd=184 file_fd=218 listen_handle=452 file_handle=180
listen_fd=88 file_fd=230 listen_handle=1220 file_handle=84
listen_fd=80 file_fd=231 listen_handle=1284 file_handle=76
listen_fd=72 file_fd=232 listen_handle=1348 file_handle=68
listen_fd=24 file_fd=238 listen_handle=1732 file_handle=20
listen_fd=16 file_fd=239 listen_handle=1796 file_handle=12
listen_fd=8 file_fd=240 listen_handle=1868 file_handle=4
listen_fd=2052 file_fd=241 listen_handle=-1 file_handle=2056
listen_fd=2060 file_fd=242 listen_handle=-1 file_handle=2064
listen_fd=2068 file_fd=243 listen_handle=-1 file_handle=2072
On this run of the program, the socket numbers (listen_fd above)
returned from subsequent socket() calls start at 1940 and keep
decreasing by eight until they reach 8, then they jump to 2056 and
start increasing. This is most likely behaviour that is not set in
stone, but just what happens on my machine right now. In other
circumstances, the socket numbers might perhaps start much lower, so
that one wouldn't need to have hundreds of sockets open to reach the
lower numbers that are likely to also be valid file descriptors.
More information about the dbus