1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
root |
1.4 |
# this file is unfortunately only executed at Makefile.PL time |
4 |
|
|
|
5 |
root |
1.7 |
use Config; |
6 |
root |
1.8 |
|
7 |
|
|
# when built as part of perl, these are not available |
8 |
|
|
BEGIN { eval "use Socket ()" } |
9 |
|
|
BEGIN { eval "use Fcntl ()" } |
10 |
root |
1.6 |
|
11 |
root |
1.3 |
open my $fh, ">lib/AnyEvent/constants.pl" |
12 |
|
|
or die "lib/AnyEvent/constants.pl: $_[0]\n"; |
13 |
|
|
|
14 |
|
|
my $oldstdout = select $fh; |
15 |
root |
1.1 |
|
16 |
root |
1.7 |
print "# automatically generated from constants.pl.PL for perl $] built for $Config{archname}\n"; |
17 |
|
|
|
18 |
root |
1.1 |
sub i($$) { |
19 |
root |
1.7 |
print "sub $_[0](){", $_[1]*1, "}\n"; |
20 |
root |
1.1 |
} |
21 |
|
|
|
22 |
root |
1.6 |
sub n($$) { |
23 |
root |
1.7 |
print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n"; |
24 |
root |
1.6 |
} |
25 |
|
|
|
26 |
root |
1.1 |
print "package AnyEvent;\n"; |
27 |
|
|
|
28 |
|
|
our $WIN32 = $^O =~ /mswin32/i; |
29 |
|
|
|
30 |
root |
1.7 |
# used a lot |
31 |
root |
1.1 |
i CYGWIN => $^O =~ /cygwin/i; |
32 |
|
|
i WIN32 => $WIN32; |
33 |
|
|
|
34 |
root |
1.7 |
# add these purely to avoid loading Fcntl, which is slow and bloated. |
35 |
root |
1.1 |
|
36 |
root |
1.8 |
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 |
root |
1.1 |
|
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 |
root |
1.7 |
$af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be |
58 |
|
|
$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ... |
59 |
root |
1.1 |
|
60 |
root |
1.7 |
# ... or isn't, because nobody has it installed |
61 |
root |
1.1 |
$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 |
root |
1.7 |
#TODO: EDOM/ESPIPE |
68 |
|
|
#TODO: maybe move socket stuff to Socket::? |
69 |
root |
1.1 |
|
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 |
root |
1.7 |
print "package AnyEvent::Socket;\n"; |
81 |
|
|
|
82 |
root |
1.6 |
# 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 |
root |
1.1 |
print "1;\n"; |
105 |
|
|
|
106 |
root |
1.3 |
close $fh; |
107 |
|
|
select $oldstdout; |
108 |
|
|
|
109 |
root |
1.6 |
1 |
110 |
root |
1.3 |
|
111 |
root |
1.6 |
__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 |