ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/constants.pl.PL
Revision: 1.13
Committed: Tue Jul 30 23:14:32 2013 UTC (11 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.12: +36 -7 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.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 use Config;
40
41 print "# generated for perl $] built for $Config{archname}\n";
42
43 # when built as part of perl, these are not available
44 BEGIN { eval "use Socket ()" }
45 BEGIN { eval "use Fcntl ()" }
46 BEGIN { eval "use POSIX ()" }
47
48 sub i($$) {
49 print "sub $_[0](){", $_[1]*1, "}\n";
50 }
51
52 sub n($$) {
53 print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n";
54 }
55
56 print "package AnyEvent;\n";
57
58 our $WIN32 = $^O =~ /mswin32/i;
59
60 # used a lot
61 i CYGWIN => $^O =~ /cygwin/i;
62 i WIN32 => $WIN32;
63
64 # add these purely to avoid loading Fcntl, which is slow and bloated.
65
66 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
71 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 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 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 $af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be
104 $af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ...
105
106 # ... or isn't, because nobody has it installed
107 $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 #TODO: EDOM/ESPIPE
114 #TODO: maybe move socket stuff to Socket::?
115
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 print "package AnyEvent::Socket;\n";
127
128 # 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 print "1;\n";
151
152 close $fh;
153 select $oldstdout;
154
155 1
156
157 __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