ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/constants.pl.PL
Revision: 1.16
Committed: Mon Feb 13 14:51:42 2017 UTC (7 years, 2 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-7_16, rel-7_15, rel-7_14, HEAD
Changes since 1.15: +3 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 # this file is unfortunately only executed at Makefile.PL time
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.74
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 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 ()" }
44
45 sub i($$) {
46 print "sub $_[0](){", $_[1]*1, "}\n";
47 }
48
49 sub n($$) {
50 print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n";
51 }
52
53 print "package AnyEvent;\n";
54
55 our $WIN32 = $^O =~ /mswin32/i;
56
57 # used a lot
58 i CYGWIN => $^O =~ /cygwin/i;
59 i WIN32 => $WIN32;
60
61 # add these purely to avoid loading Fcntl, which is slow and bloated.
62
63 i F_SETFD => eval { Fcntl::F_SETFD() } || 2;
64 i F_SETFL => eval { Fcntl::F_SETFL() } || 4;
65 i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() } || 04000;
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;
83
84 print "package AnyEvent::Util;\n";
85
86 # broken windows perls use undocumented error codes...
87 if ($WIN32) {
88 i WSAEINVAL => 10022;
89 i WSAEWOULDBLOCK => 10035;
90 i WSAEINPROGRESS => 10036;
91 } else {
92 # these should never match any errno value
93 i WSAEINVAL => -1e99;
94 i WSAEWOULDBLOCK => -1e99;
95 i WSAEINPROGRESS => -1e99;
96 }
97
98 my $af_inet6;
99
100 $af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be
101 $af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ...
102
103 # ... or isn't, because nobody has it installed
104 $af_inet6 ||= 10 if $^O =~ /linux/;
105 $af_inet6 ||= 23 if $^O =~ /cygwin/i;
106 $af_inet6 ||= 23 if AnyEvent::WIN32;
107 $af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/;
108 $af_inet6 ||= 28 if $^O =~ /freebsd/;
109
110 #TODO: EDOM/ESPIPE
111 #TODO: maybe move socket stuff to Socket::?
112
113 i _AF_INET6 => $af_inet6;
114 #i AF_UNIX => Socket::AF_UNIX ();
115 #i SOCK_STREAM => Socket::SOCK_STREAM ();
116 #i SOCK_DGRAM => Socket::SOCK_DGRAM ();
117 #i SOL_SOCKET => Socket::SOL_SOCKET ();
118 #i SO_REUSEADDR => Socket::SO_REUSEADDR ();
119 #i SO_KEEPALIVE => Socket::SO_KEEPALIVE ();
120 #i SO_OOBINLINE => Socket::SO_OOBINLINE ();
121 #i IPPROTO_TCP => Socket::IPPROTO_TCP ();
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
147 print "1;\n";
148
149 close $fh;
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 linux TCP_FASTOPEN 23
169 linux MSG_DONTWAIT 0x0040
170 linux MSG_NOSIGNAL 0x4000
171 linux MSG_MORE 0x8000
172 linux MSG_FASTOPEN 0x20000000
173 netbsd TCP_MAXSEG 2
174 netbsd TCP_KEEPIDLE 3
175 netbsd TCP_NOPUSH 4
176 netbsd TCP_KEEPINTVL 5
177 netbsd TCP_KEEPCNT 6
178 netbsd TCP_KEEPINIT 7
179 netbsd TCP_NOOPT 8
180 netbsd TCP_MD5SIG 0x10
181 netbsd TCP_CONGESTION 0x20
182 netbsd MSG_NOSIGNAL 0x0400
183 cygwin TCP_MAXSEG 0x02
184 cygwin TCP_NOPUSH 0x04
185 cygwin TCP_NOOPT 0x08
186 freebsd TCP_MAXSEG 0x02
187 freebsd TCP_NOPUSH 0x04
188 freebsd TCP_NOOPT 0x08
189 freebsd TCP_MD5SIG 0x10
190 freebsd TCP_INFO 0x20
191 freebsd TCP_CONGESTION 0x40
192 freebsd MSG_NOSIGNAL 0x20000
193 solaris TCP_CORK 0x18
194 solaris TCP_LINGER2 0x1C
195 solaris TCP_INIT_CWND 0x15
196 solaris TCP_KEEPALIVE 0x8
197 solaris TCP_MAXSEG 0x02
198 openbsd TCP_MAXSEG 0x02
199 openbsd TCP_MD5SIG 0x04
200 openbsd TCP_SACK_ENABLE 0x08
201 darwin TCP_MAXSEG 0x02
202 darwin TCP_NOPUSH 0x04
203 darwin TCP_NOOPT 0x08
204 darwin TCP_KEEPALIVE 0x10
205 darwin TCP_CONNECTIONTIMEOUT 0x20