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.7 by root, Mon Oct 11 04:17:55 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines