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.10 by root, Sun Dec 5 11:41:45 2010 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
5use Config;
6
7# when built as part of perl, these are not available
8BEGIN { eval "use Socket ()" }
9BEGIN { eval "use Fcntl ()" }
10BEGIN { eval "use POSIX ()" }
4 11
5open my $fh, ">lib/AnyEvent/constants.pl" 12open my $fh, ">lib/AnyEvent/constants.pl"
6 or die "lib/AnyEvent/constants.pl: $_[0]\n"; 13 or die "lib/AnyEvent/constants.pl: $_[0]\n";
7 14
8my $oldstdout = select $fh; 15my $oldstdout = select $fh;
9 16
17print "# automatically generated from constants.pl.PL for perl $] built for $Config{archname}\n";
18
10sub i($$) { 19sub i($$) {
11 print "sub $_[0] () { ", $_[1]*1, " }\n"; 20 print "sub $_[0](){", $_[1]*1, "}\n";
21}
22
23sub n($$) {
24 print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n";
12} 25}
13 26
14print "package AnyEvent;\n"; 27print "package AnyEvent;\n";
15 28
16our $WIN32 = $^O =~ /mswin32/i; 29our $WIN32 = $^O =~ /mswin32/i;
17 30
31# used a lot
18i CYGWIN => $^O =~ /cygwin/i; 32i CYGWIN => $^O =~ /cygwin/i;
19i WIN32 => $WIN32; 33i WIN32 => $WIN32;
20 34
21use Fcntl (); 35# add these purely to avoid loading Fcntl, which is slow and bloated.
22 36
23i F_SETFL => eval { Fcntl::F_SETFL() };
24i F_SETFD => eval { Fcntl::F_SETFD() }; 37i F_SETFD => eval { Fcntl::F_SETFD() } || 2;
38i F_SETFL => eval { Fcntl::F_SETFL() } || 4;
25i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() }; 39i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() } || 04000;
26i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() }; 40i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() } || 1;
41
42print "package AnyEvent::Base;\n";
43
44# add these purely to avoid loading POSIX, which is slow and bloated.
45
46i WNOHANG => eval { POSIX::WNOHANG() } || 1;
27 47
28print "package AnyEvent::Util;\n"; 48print "package AnyEvent::Util;\n";
29 49
30# broken windows perls use undocumented error codes... 50# broken windows perls use undocumented error codes...
31if ($WIN32) { 51if ($WIN32) {
39 i WSAEINPROGRESS => -1e99; 59 i WSAEINPROGRESS => -1e99;
40} 60}
41 61
42my $af_inet6; 62my $af_inet6;
43 63
44$af_inet6 ||= eval { require Socket ; Socket::AF_INET6 () }; 64$af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be
45$af_ine6t ||= eval { require Socket6; Socket6::AF_INET6() }; 65$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ...
46 66
47# uhoh 67# ... or isn't, because nobody has it installed
48$af_inet6 ||= 10 if $^O =~ /linux/; 68$af_inet6 ||= 10 if $^O =~ /linux/;
49$af_inet6 ||= 23 if $^O =~ /cygwin/i; 69$af_inet6 ||= 23 if $^O =~ /cygwin/i;
50$af_inet6 ||= 23 if AnyEvent::WIN32; 70$af_inet6 ||= 23 if AnyEvent::WIN32;
51$af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/; 71$af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/;
52$af_inet6 ||= 28 if $^O =~ /freebsd/; 72$af_inet6 ||= 28 if $^O =~ /freebsd/;
53 73
54#TODO: WSAxxx, EDOM/ESPIPE 74#TODO: EDOM/ESPIPE
75#TODO: maybe move socket stuff to Socket::?
55 76
56i _AF_INET6 => $af_inet6; 77i _AF_INET6 => $af_inet6;
57#i AF_UNIX => Socket::AF_UNIX (); 78#i AF_UNIX => Socket::AF_UNIX ();
58#i SOCK_STREAM => Socket::SOCK_STREAM (); 79#i SOCK_STREAM => Socket::SOCK_STREAM ();
59#i SOCK_DGRAM => Socket::SOCK_DGRAM (); 80#i SOCK_DGRAM => Socket::SOCK_DGRAM ();
61#i SO_REUSEADDR => Socket::SO_REUSEADDR (); 82#i SO_REUSEADDR => Socket::SO_REUSEADDR ();
62#i SO_KEEPALIVE => Socket::SO_KEEPALIVE (); 83#i SO_KEEPALIVE => Socket::SO_KEEPALIVE ();
63#i SO_OOBINLINE => Socket::SO_OOBINLINE (); 84#i SO_OOBINLINE => Socket::SO_OOBINLINE ();
64#i IPPROTO_TCP => Socket::IPPROTO_TCP (); 85#i IPPROTO_TCP => Socket::IPPROTO_TCP ();
65 86
87print "package AnyEvent::Socket;\n";
88
89# more hardcoded os-specific constants - none
90# of these are available via any known module, but we
91# are forward-looking and try Socket:: anyways.
92my %const;
93
94while (<DATA>) {
95 my ($os, $name, $default) = split /\s+/;
96
97 $const{$name} ||= undef; # make sure it exists
98
99 next unless $os eq $^O;
100
101 my $value = eval "Socket::$name ()";
102 $value = eval $default unless defined $value;
103
104 $const{$name} = $value;
105}
106
107for my $k (sort keys %const) {
108 n $k, $const{$k};
109}
110
66print "1;\n"; 111print "1;\n";
67 112
68close $fh; 113close $fh;
69select $oldstdout; 114select $oldstdout;
70 115
71rename "$ARGV[0]~", $ARGV[0]; 1161
72 117
731 118__DATA__
119linux TCP_MAXSEG 2
120linux TCP_CORK 3
121linux TCP_KEEPIDLE 4
122linux TCP_KEEPINTVL 5
123linux TCP_KEEPCNT 6
124linux TCP_SYNCNT 7
125linux TCP_LINGER2 8
126linux TCP_DEFER_ACCEPT 9
127linux TCP_WINDOW_CLAMP 10
128linux TCP_INFO 11
129linux TCP_QUICKACK 12
130linux TCP_CONGESTION 13
131linux TCP_MD5SIG 14
132netbsd TCP_MAXSEG 2
133netbsd TCP_KEEPIDLE 3
134netbsd TCP_NOPUSH 4
135netbsd TCP_KEEPINTVL 5
136netbsd TCP_KEEPCNT 6
137netbsd TCP_KEEPINIT 7
138netbsd TCP_NOOPT 8
139netbsd TCP_MD5SIG 0x10
140netbsd TCP_CONGESTION 0x20
141cygwin TCP_MAXSEG 0x02
142cygwin TCP_NOPUSH 0x04
143cygwin TCP_NOOPT 0x08
144freebsd TCP_MAXSEG 0x02
145freebsd TCP_NOPUSH 0x04
146freebsd TCP_NOOPT 0x08
147freebsd TCP_MD5SIG 0x10
148freebsd TCP_INFO 0x20
149freebsd TCP_CONGESTION 0x40
150solaris TCP_CORK 0x18
151solaris TCP_LINGER2 0x1C
152solaris TCP_INIT_CWND 0x15
153solaris TCP_KEEPALIVE 0x8
154solaris TCP_MAXSEG 0x02
155openbsd TCP_MAXSEG 0x02
156openbsd TCP_MD5SIG 0x04
157openbsd TCP_SACK_ENABLE 0x08
158darwin TCP_MAXSEG 0x02
159darwin TCP_NOPUSH 0x04
160darwin TCP_NOOPT 0x08
161darwin TCP_KEEPALIVE 0x10
162darwin TCP_CONNECTIONTIMEOUT 0x20

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines