in reply to Detect socket
sub dbconnect { socket(my $mysocket, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die("socket: $!"); fileno($mysocket) >= 100 or die("No available file descriptors below 100\n"); # ... }
Update: Here's a test that checks if the above works:
use strict; use warnings; use Socket; my @handles; for (0..9) { open($handles[$_], '<', $0) or die; print("$_: ", fileno($handles[$_]), "\n"); } print("--\n"); close($handles[5]); socket(my $mysocket, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or d +ie; print(fileno($mysocket), "\n");
Works on my system:
0: 3 1: 4 2: 6 3: 8 4: 9 5: 10 6: 11 7: 12 8: 13 9: 14 -- 10
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Detect socket
by motzi (Sexton) on Apr 21, 2010 at 21:08 UTC | |
by ikegami (Patriarch) on Apr 21, 2010 at 21:11 UTC | |
by ikegami (Patriarch) on Apr 21, 2010 at 21:19 UTC | |
by apl (Monsignor) on Apr 22, 2010 at 12:20 UTC |