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