1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | # this file is unfortunately only executed at Makefile.PL time |
3 | # this file is unfortunately only executed at Makefile.PL time |
4 | |
4 | |
|
|
5 | use Config; |
5 | use Socket; |
6 | use Socket; |
6 | |
7 | |
7 | open my $fh, ">lib/AnyEvent/constants.pl" |
8 | open my $fh, ">lib/AnyEvent/constants.pl" |
8 | or die "lib/AnyEvent/constants.pl: $_[0]\n"; |
9 | or die "lib/AnyEvent/constants.pl: $_[0]\n"; |
9 | |
10 | |
10 | my $oldstdout = select $fh; |
11 | my $oldstdout = select $fh; |
11 | |
12 | |
|
|
13 | print "# automatically generated from constants.pl.PL for perl $] built for $Config{archname}\n"; |
|
|
14 | |
12 | sub i($$) { |
15 | sub i($$) { |
13 | print "sub $_[0] () { ", $_[1]*1, " }\n"; |
16 | print "sub $_[0](){", $_[1]*1, "}\n"; |
14 | } |
17 | } |
15 | |
18 | |
16 | sub n($$) { |
19 | sub n($$) { |
17 | print "sub $_[0] () { ", (defined $_[1] ? $_[1]*1 : "undef"), " }\n"; |
20 | print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n"; |
18 | } |
21 | } |
19 | |
22 | |
20 | print "package AnyEvent;\n"; |
23 | print "package AnyEvent;\n"; |
21 | |
24 | |
22 | our $WIN32 = $^O =~ /mswin32/i; |
25 | our $WIN32 = $^O =~ /mswin32/i; |
23 | |
26 | |
|
|
27 | # used a lot |
24 | i CYGWIN => $^O =~ /cygwin/i; |
28 | i CYGWIN => $^O =~ /cygwin/i; |
25 | i WIN32 => $WIN32; |
29 | i WIN32 => $WIN32; |
26 | |
30 | |
|
|
31 | # add these purely to avoid loading Fcntl, which is slow and bloated. |
27 | use Fcntl (); |
32 | use Fcntl (); |
28 | |
33 | |
29 | i F_SETFL => eval { Fcntl::F_SETFL() }; |
34 | i F_SETFL => eval { Fcntl::F_SETFL() }; |
30 | i F_SETFD => eval { Fcntl::F_SETFD() }; |
35 | i F_SETFD => eval { Fcntl::F_SETFD() }; |
31 | i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() }; |
36 | i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() }; |
… | |
… | |
45 | i WSAEINPROGRESS => -1e99; |
50 | i WSAEINPROGRESS => -1e99; |
46 | } |
51 | } |
47 | |
52 | |
48 | my $af_inet6; |
53 | my $af_inet6; |
49 | |
54 | |
50 | $af_inet6 ||= eval { Socket::AF_INET6 () }; |
55 | $af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be |
51 | $af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; |
56 | $af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ... |
52 | |
57 | |
53 | # uhoh |
58 | # ... or isn't, because nobody has it installed |
54 | $af_inet6 ||= 10 if $^O =~ /linux/; |
59 | $af_inet6 ||= 10 if $^O =~ /linux/; |
55 | $af_inet6 ||= 23 if $^O =~ /cygwin/i; |
60 | $af_inet6 ||= 23 if $^O =~ /cygwin/i; |
56 | $af_inet6 ||= 23 if AnyEvent::WIN32; |
61 | $af_inet6 ||= 23 if AnyEvent::WIN32; |
57 | $af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/; |
62 | $af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/; |
58 | $af_inet6 ||= 28 if $^O =~ /freebsd/; |
63 | $af_inet6 ||= 28 if $^O =~ /freebsd/; |
59 | |
64 | |
60 | #TODO: WSAxxx, EDOM/ESPIPE |
65 | #TODO: EDOM/ESPIPE |
|
|
66 | #TODO: maybe move socket stuff to Socket::? |
61 | |
67 | |
62 | i _AF_INET6 => $af_inet6; |
68 | i _AF_INET6 => $af_inet6; |
63 | #i AF_UNIX => Socket::AF_UNIX (); |
69 | #i AF_UNIX => Socket::AF_UNIX (); |
64 | #i SOCK_STREAM => Socket::SOCK_STREAM (); |
70 | #i SOCK_STREAM => Socket::SOCK_STREAM (); |
65 | #i SOCK_DGRAM => Socket::SOCK_DGRAM (); |
71 | #i SOCK_DGRAM => Socket::SOCK_DGRAM (); |
66 | #i SOL_SOCKET => Socket::SOL_SOCKET (); |
72 | #i SOL_SOCKET => Socket::SOL_SOCKET (); |
67 | #i SO_REUSEADDR => Socket::SO_REUSEADDR (); |
73 | #i SO_REUSEADDR => Socket::SO_REUSEADDR (); |
68 | #i SO_KEEPALIVE => Socket::SO_KEEPALIVE (); |
74 | #i SO_KEEPALIVE => Socket::SO_KEEPALIVE (); |
69 | #i SO_OOBINLINE => Socket::SO_OOBINLINE (); |
75 | #i SO_OOBINLINE => Socket::SO_OOBINLINE (); |
70 | #i IPPROTO_TCP => Socket::IPPROTO_TCP (); |
76 | #i IPPROTO_TCP => Socket::IPPROTO_TCP (); |
|
|
77 | |
|
|
78 | print "package AnyEvent::Socket;\n"; |
71 | |
79 | |
72 | # more hardcoded os-specific constants - none |
80 | # more hardcoded os-specific constants - none |
73 | # of these are available via any known module, but we |
81 | # of these are available via any known module, but we |
74 | # are forward-looking and try Socket:: anyways. |
82 | # are forward-looking and try Socket:: anyways. |
75 | my %const; |
83 | my %const; |