ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/constants.pl.PL
Revision: 1.8
Committed: Mon Nov 22 06:32:18 2010 UTC (14 years ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.7: +8 -5 lines
Log Message:
*** empty log message ***

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