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.4 by root, Sat Mar 13 00:09:28 2010 UTC vs.
Revision 1.13 by root, Tue Jul 30 23:14:32 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines