1 |
#! perl |
2 |
|
3 |
# this file is unfortunately only executed at Makefile.PL time |
4 |
|
5 |
use Config; |
6 |
|
7 |
# when built as part of perl, these are not available |
8 |
BEGIN { eval "use Socket ()" } |
9 |
BEGIN { eval "use Fcntl ()" } |
10 |
BEGIN { eval "use POSIX ()" } |
11 |
|
12 |
open my $fh, ">lib/AnyEvent/constants.pl" |
13 |
or die "lib/AnyEvent/constants.pl: $!\n"; |
14 |
|
15 |
my $oldstdout = select $fh; |
16 |
|
17 |
print "# automatically generated from constants.pl.PL for perl $] built for $Config{archname}\n"; |
18 |
|
19 |
sub i($$) { |
20 |
print "sub $_[0](){", $_[1]*1, "}\n"; |
21 |
} |
22 |
|
23 |
sub n($$) { |
24 |
print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n"; |
25 |
} |
26 |
|
27 |
print "package AnyEvent;\n"; |
28 |
|
29 |
our $WIN32 = $^O =~ /mswin32/i; |
30 |
|
31 |
# used a lot |
32 |
i CYGWIN => $^O =~ /cygwin/i; |
33 |
i WIN32 => $WIN32; |
34 |
|
35 |
# add these purely to avoid loading Fcntl, which is slow and bloated. |
36 |
|
37 |
i F_SETFD => eval { Fcntl::F_SETFD() } || 2; |
38 |
i F_SETFL => eval { Fcntl::F_SETFL() } || 4; |
39 |
i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() } || 04000; |
40 |
i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() } || 1; |
41 |
|
42 |
print "package AnyEvent::Base;\n"; |
43 |
|
44 |
# add these purely to avoid loading POSIX, which is slow and bloated. |
45 |
|
46 |
i WNOHANG => eval { POSIX::WNOHANG() } || 1; |
47 |
|
48 |
print "package AnyEvent::IO;\n"; |
49 |
|
50 |
i O_RDONLY => eval { Fcntl::O_RDONLY() } || 0; |
51 |
i O_WRONLY => eval { Fcntl::O_WRONLY() } || 1; |
52 |
i O_RDWR => eval { Fcntl::O_RDWR () } || 2; |
53 |
i O_CREAT => eval { Fcntl::O_CREAT () } || 64; |
54 |
i O_EXCL => eval { Fcntl::O_EXCL () } || 128; |
55 |
i O_TRUNC => eval { Fcntl::O_TRUNC () } || 512; |
56 |
i O_APPEND => eval { Fcntl::O_APPEND() } || 1024; |
57 |
|
58 |
print "package AnyEvent::Util;\n"; |
59 |
|
60 |
# broken windows perls use undocumented error codes... |
61 |
if ($WIN32) { |
62 |
i WSAEINVAL => 10022; |
63 |
i WSAEWOULDBLOCK => 10035; |
64 |
i WSAEINPROGRESS => 10036; |
65 |
} else { |
66 |
# these should never match any errno value |
67 |
i WSAEINVAL => -1e99; |
68 |
i WSAEWOULDBLOCK => -1e99; |
69 |
i WSAEINPROGRESS => -1e99; |
70 |
} |
71 |
|
72 |
my $af_inet6; |
73 |
|
74 |
$af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be |
75 |
$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ... |
76 |
|
77 |
# ... or isn't, because nobody has it installed |
78 |
$af_inet6 ||= 10 if $^O =~ /linux/; |
79 |
$af_inet6 ||= 23 if $^O =~ /cygwin/i; |
80 |
$af_inet6 ||= 23 if AnyEvent::WIN32; |
81 |
$af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/; |
82 |
$af_inet6 ||= 28 if $^O =~ /freebsd/; |
83 |
|
84 |
#TODO: EDOM/ESPIPE |
85 |
#TODO: maybe move socket stuff to Socket::? |
86 |
|
87 |
i _AF_INET6 => $af_inet6; |
88 |
#i AF_UNIX => Socket::AF_UNIX (); |
89 |
#i SOCK_STREAM => Socket::SOCK_STREAM (); |
90 |
#i SOCK_DGRAM => Socket::SOCK_DGRAM (); |
91 |
#i SOL_SOCKET => Socket::SOL_SOCKET (); |
92 |
#i SO_REUSEADDR => Socket::SO_REUSEADDR (); |
93 |
#i SO_KEEPALIVE => Socket::SO_KEEPALIVE (); |
94 |
#i SO_OOBINLINE => Socket::SO_OOBINLINE (); |
95 |
#i IPPROTO_TCP => Socket::IPPROTO_TCP (); |
96 |
|
97 |
print "package AnyEvent::Socket;\n"; |
98 |
|
99 |
# more hardcoded os-specific constants - none |
100 |
# of these are available via any known module, but we |
101 |
# are forward-looking and try Socket:: anyways. |
102 |
my %const; |
103 |
|
104 |
while (<DATA>) { |
105 |
my ($os, $name, $default) = split /\s+/; |
106 |
|
107 |
$const{$name} ||= undef; # make sure it exists |
108 |
|
109 |
next unless $os eq $^O; |
110 |
|
111 |
my $value = eval "Socket::$name ()"; |
112 |
$value = eval $default unless defined $value; |
113 |
|
114 |
$const{$name} = $value; |
115 |
} |
116 |
|
117 |
for my $k (sort keys %const) { |
118 |
n $k, $const{$k}; |
119 |
} |
120 |
|
121 |
print "1;\n"; |
122 |
|
123 |
close $fh; |
124 |
select $oldstdout; |
125 |
|
126 |
1 |
127 |
|
128 |
__DATA__ |
129 |
linux TCP_MAXSEG 2 |
130 |
linux TCP_CORK 3 |
131 |
linux TCP_KEEPIDLE 4 |
132 |
linux TCP_KEEPINTVL 5 |
133 |
linux TCP_KEEPCNT 6 |
134 |
linux TCP_SYNCNT 7 |
135 |
linux TCP_LINGER2 8 |
136 |
linux TCP_DEFER_ACCEPT 9 |
137 |
linux TCP_WINDOW_CLAMP 10 |
138 |
linux TCP_INFO 11 |
139 |
linux TCP_QUICKACK 12 |
140 |
linux TCP_CONGESTION 13 |
141 |
linux TCP_MD5SIG 14 |
142 |
netbsd TCP_MAXSEG 2 |
143 |
netbsd TCP_KEEPIDLE 3 |
144 |
netbsd TCP_NOPUSH 4 |
145 |
netbsd TCP_KEEPINTVL 5 |
146 |
netbsd TCP_KEEPCNT 6 |
147 |
netbsd TCP_KEEPINIT 7 |
148 |
netbsd TCP_NOOPT 8 |
149 |
netbsd TCP_MD5SIG 0x10 |
150 |
netbsd TCP_CONGESTION 0x20 |
151 |
cygwin TCP_MAXSEG 0x02 |
152 |
cygwin TCP_NOPUSH 0x04 |
153 |
cygwin TCP_NOOPT 0x08 |
154 |
freebsd TCP_MAXSEG 0x02 |
155 |
freebsd TCP_NOPUSH 0x04 |
156 |
freebsd TCP_NOOPT 0x08 |
157 |
freebsd TCP_MD5SIG 0x10 |
158 |
freebsd TCP_INFO 0x20 |
159 |
freebsd TCP_CONGESTION 0x40 |
160 |
solaris TCP_CORK 0x18 |
161 |
solaris TCP_LINGER2 0x1C |
162 |
solaris TCP_INIT_CWND 0x15 |
163 |
solaris TCP_KEEPALIVE 0x8 |
164 |
solaris TCP_MAXSEG 0x02 |
165 |
openbsd TCP_MAXSEG 0x02 |
166 |
openbsd TCP_MD5SIG 0x04 |
167 |
openbsd TCP_SACK_ENABLE 0x08 |
168 |
darwin TCP_MAXSEG 0x02 |
169 |
darwin TCP_NOPUSH 0x04 |
170 |
darwin TCP_NOOPT 0x08 |
171 |
darwin TCP_KEEPALIVE 0x10 |
172 |
darwin TCP_CONNECTIONTIMEOUT 0x20 |