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