ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/constants.pl.PL
(Generate patch)

Comparing AnyEvent/constants.pl.PL (file contents):
Revision 1.3 by root, Sat Mar 13 00:08:08 2010 UTC vs.
Revision 1.16 by root, Mon Feb 13 14:51:42 2017 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines