ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/constants.pl.PL
Revision: 1.9
Committed: Fri Nov 26 21:27:41 2010 UTC (14 years ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.8: +0 -1 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
36 i F_SETFD => eval { Fcntl::F_SETFD() } || 2;
37 i F_SETFL => eval { Fcntl::F_SETFL() } || 4;
38 i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() } || 04000;
39 i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() } || 1;
40
41 print "package AnyEvent::Util;\n";
42
43 # broken windows perls use undocumented error codes...
44 if ($WIN32) {
45 i WSAEINVAL => 10022;
46 i WSAEWOULDBLOCK => 10035;
47 i WSAEINPROGRESS => 10036;
48 } else {
49 # these should never match any errno value
50 i WSAEINVAL => -1e99;
51 i WSAEWOULDBLOCK => -1e99;
52 i WSAEINPROGRESS => -1e99;
53 }
54
55 my $af_inet6;
56
57 $af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be
58 $af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ...
59
60 # ... or isn't, because nobody has it installed
61 $af_inet6 ||= 10 if $^O =~ /linux/;
62 $af_inet6 ||= 23 if $^O =~ /cygwin/i;
63 $af_inet6 ||= 23 if AnyEvent::WIN32;
64 $af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/;
65 $af_inet6 ||= 28 if $^O =~ /freebsd/;
66
67 #TODO: EDOM/ESPIPE
68 #TODO: maybe move socket stuff to Socket::?
69
70 i _AF_INET6 => $af_inet6;
71 #i AF_UNIX => Socket::AF_UNIX ();
72 #i SOCK_STREAM => Socket::SOCK_STREAM ();
73 #i SOCK_DGRAM => Socket::SOCK_DGRAM ();
74 #i SOL_SOCKET => Socket::SOL_SOCKET ();
75 #i SO_REUSEADDR => Socket::SO_REUSEADDR ();
76 #i SO_KEEPALIVE => Socket::SO_KEEPALIVE ();
77 #i SO_OOBINLINE => Socket::SO_OOBINLINE ();
78 #i IPPROTO_TCP => Socket::IPPROTO_TCP ();
79
80 print "package AnyEvent::Socket;\n";
81
82 # more hardcoded os-specific constants - none
83 # of these are available via any known module, but we
84 # are forward-looking and try Socket:: anyways.
85 my %const;
86
87 while (<DATA>) {
88 my ($os, $name, $default) = split /\s+/;
89
90 $const{$name} ||= undef; # make sure it exists
91
92 next unless $os eq $^O;
93
94 my $value = eval "Socket::$name ()";
95 $value = eval $default unless defined $value;
96
97 $const{$name} = $value;
98 }
99
100 for my $k (sort keys %const) {
101 n $k, $const{$k};
102 }
103
104 print "1;\n";
105
106 close $fh;
107 select $oldstdout;
108
109 1
110
111 __DATA__
112 linux TCP_MAXSEG 2
113 linux TCP_CORK 3
114 linux TCP_KEEPIDLE 4
115 linux TCP_KEEPINTVL 5
116 linux TCP_KEEPCNT 6
117 linux TCP_SYNCNT 7
118 linux TCP_LINGER2 8
119 linux TCP_DEFER_ACCEPT 9
120 linux TCP_WINDOW_CLAMP 10
121 linux TCP_INFO 11
122 linux TCP_QUICKACK 12
123 linux TCP_CONGESTION 13
124 linux TCP_MD5SIG 14
125 netbsd TCP_MAXSEG 2
126 netbsd TCP_KEEPIDLE 3
127 netbsd TCP_NOPUSH 4
128 netbsd TCP_KEEPINTVL 5
129 netbsd TCP_KEEPCNT 6
130 netbsd TCP_KEEPINIT 7
131 netbsd TCP_NOOPT 8
132 netbsd TCP_MD5SIG 0x10
133 netbsd TCP_CONGESTION 0x20
134 cygwin TCP_MAXSEG 0x02
135 cygwin TCP_NOPUSH 0x04
136 cygwin TCP_NOOPT 0x08
137 freebsd TCP_MAXSEG 0x02
138 freebsd TCP_NOPUSH 0x04
139 freebsd TCP_NOOPT 0x08
140 freebsd TCP_MD5SIG 0x10
141 freebsd TCP_INFO 0x20
142 freebsd TCP_CONGESTION 0x40
143 solaris TCP_CORK 0x18
144 solaris TCP_LINGER2 0x1C
145 solaris TCP_INIT_CWND 0x15
146 solaris TCP_KEEPALIVE 0x8
147 solaris TCP_MAXSEG 0x02
148 openbsd TCP_MAXSEG 0x02
149 openbsd TCP_MD5SIG 0x04
150 openbsd TCP_SACK_ENABLE 0x08
151 darwin TCP_MAXSEG 0x02
152 darwin TCP_NOPUSH 0x04
153 darwin TCP_NOOPT 0x08
154 darwin TCP_KEEPALIVE 0x10
155 darwin TCP_CONNECTIONTIMEOUT 0x20