D
Dean Arnold
I've got an app that calls an external
3rd party C lib that opens sockets, but doesn't expose the sockets
directly outside of the library. I want to use the fileno's
of those sockets in a Perl select(read,write,error,timeout) call.
so I need to discover the fileno's of the sockets.
Q: will something like the following do what I need
(esp. on both Win32 and *nix) ? The upper fileno limit
is arbitrary, and can probably be tuned as needed.
@fdary = ();
foreach (0..23) {
$fdary[$_] = 1, next
unless open FH, "<&$_";
close FH;
}
foreach (0..$#fdary) {
print "$_ is available\n"
if defined($fdary[$_]);
}
The idea would be to scan once before
calling the external lib to open a socket,
then scan again, skipping the entries we know are
already open. The difference between
pre- and post- sets of dup'able handles is
assumed to be the fileno's of the new sockets.
It seems to work for files openned via Perl, but are
the fileno's generated via Perl identical to the underlying OS's
file descriptors ? esp. for Win32 ?
Is there a way to do this with a zero-timeout select() or poll()
(ie, set the bitmask to all fileno's, then scan for any fileno's
which report errors ?)
Is there a simpler solution (other than lsof, which
AFAIK doesn't exist in Win32) ? Google didn't provide
any promising results.
TIA,
Dean Arnold
Presicient Corp.
www.presicient.com
3rd party C lib that opens sockets, but doesn't expose the sockets
directly outside of the library. I want to use the fileno's
of those sockets in a Perl select(read,write,error,timeout) call.
so I need to discover the fileno's of the sockets.
Q: will something like the following do what I need
(esp. on both Win32 and *nix) ? The upper fileno limit
is arbitrary, and can probably be tuned as needed.
@fdary = ();
foreach (0..23) {
$fdary[$_] = 1, next
unless open FH, "<&$_";
close FH;
}
foreach (0..$#fdary) {
print "$_ is available\n"
if defined($fdary[$_]);
}
The idea would be to scan once before
calling the external lib to open a socket,
then scan again, skipping the entries we know are
already open. The difference between
pre- and post- sets of dup'able handles is
assumed to be the fileno's of the new sockets.
It seems to work for files openned via Perl, but are
the fileno's generated via Perl identical to the underlying OS's
file descriptors ? esp. for Win32 ?
Is there a way to do this with a zero-timeout select() or poll()
(ie, set the bitmask to all fileno's, then scan for any fileno's
which report errors ?)
Is there a simpler solution (other than lsof, which
AFAIK doesn't exist in Win32) ? Google didn't provide
any promising results.
TIA,
Dean Arnold
Presicient Corp.
www.presicient.com