ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/constants.pl.PL
Revision: 1.10
Committed: Sun Dec 5 11:41:45 2010 UTC (14 years ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-5_29, rel-6_0, rel-6_1, rel-5_3, rel-6_14, rel-6_11, rel-6_12, rel-6_13, rel-5_31, rel-6_02, rel-6_01
Changes since 1.9: +7 -0 lines
Log Message:
5.29

File Contents

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