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