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 Socket; |
4 | |
6 | |
5 | open my $fh, ">lib/AnyEvent/constants.pl" |
7 | open my $fh, ">lib/AnyEvent/constants.pl" |
6 | or die "lib/AnyEvent/constants.pl: $_[0]\n"; |
8 | or die "lib/AnyEvent/constants.pl: $_[0]\n"; |
7 | |
9 | |
8 | my $oldstdout = select $fh; |
10 | my $oldstdout = select $fh; |
9 | |
11 | |
10 | sub i($$) { |
12 | sub i($$) { |
11 | print "sub $_[0] () { ", $_[1]*1, " }\n"; |
13 | print "sub $_[0] () { ", $_[1]*1, " }\n"; |
|
|
14 | } |
|
|
15 | |
|
|
16 | sub n($$) { |
|
|
17 | print "sub $_[0] () { ", (defined $_[1] ? $_[1]*1 : "undef"), " }\n"; |
12 | } |
18 | } |
13 | |
19 | |
14 | print "package AnyEvent;\n"; |
20 | print "package AnyEvent;\n"; |
15 | |
21 | |
16 | our $WIN32 = $^O =~ /mswin32/i; |
22 | our $WIN32 = $^O =~ /mswin32/i; |
… | |
… | |
39 | i WSAEINPROGRESS => -1e99; |
45 | i WSAEINPROGRESS => -1e99; |
40 | } |
46 | } |
41 | |
47 | |
42 | my $af_inet6; |
48 | my $af_inet6; |
43 | |
49 | |
44 | $af_inet6 ||= eval { require Socket ; Socket::AF_INET6 () }; |
50 | $af_inet6 ||= eval { Socket::AF_INET6 () }; |
45 | $af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; |
51 | $af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; |
46 | |
52 | |
47 | # uhoh |
53 | # uhoh |
48 | $af_inet6 ||= 10 if $^O =~ /linux/; |
54 | $af_inet6 ||= 10 if $^O =~ /linux/; |
49 | $af_inet6 ||= 23 if $^O =~ /cygwin/i; |
55 | $af_inet6 ||= 23 if $^O =~ /cygwin/i; |
… | |
… | |
61 | #i SO_REUSEADDR => Socket::SO_REUSEADDR (); |
67 | #i SO_REUSEADDR => Socket::SO_REUSEADDR (); |
62 | #i SO_KEEPALIVE => Socket::SO_KEEPALIVE (); |
68 | #i SO_KEEPALIVE => Socket::SO_KEEPALIVE (); |
63 | #i SO_OOBINLINE => Socket::SO_OOBINLINE (); |
69 | #i SO_OOBINLINE => Socket::SO_OOBINLINE (); |
64 | #i IPPROTO_TCP => Socket::IPPROTO_TCP (); |
70 | #i IPPROTO_TCP => Socket::IPPROTO_TCP (); |
65 | |
71 | |
|
|
72 | # more hardcoded os-specific constants - none |
|
|
73 | # of these are available via any known module, but we |
|
|
74 | # are forward-looking and try Socket:: anyways. |
|
|
75 | my %const; |
|
|
76 | |
|
|
77 | while (<DATA>) { |
|
|
78 | my ($os, $name, $default) = split /\s+/; |
|
|
79 | |
|
|
80 | $const{$name} ||= undef; # make sure it exists |
|
|
81 | |
|
|
82 | next unless $os eq $^O; |
|
|
83 | |
|
|
84 | my $value = eval "Socket::$name ()"; |
|
|
85 | $value = eval $default unless defined $value; |
|
|
86 | |
|
|
87 | $const{$name} = $value; |
|
|
88 | } |
|
|
89 | |
|
|
90 | for my $k (sort keys %const) { |
|
|
91 | n $k, $const{$k}; |
|
|
92 | } |
|
|
93 | |
66 | print "1;\n"; |
94 | print "1;\n"; |
67 | |
95 | |
68 | close $fh; |
96 | close $fh; |
69 | select $oldstdout; |
97 | select $oldstdout; |
70 | |
98 | |
71 | rename "$ARGV[0]~", $ARGV[0]; |
99 | 1 |
72 | |
100 | |
73 | 1 |
101 | __DATA__ |
|
|
102 | linux TCP_MAXSEG 2 |
|
|
103 | linux TCP_CORK 3 |
|
|
104 | linux TCP_KEEPIDLE 4 |
|
|
105 | linux TCP_KEEPINTVL 5 |
|
|
106 | linux TCP_KEEPCNT 6 |
|
|
107 | linux TCP_SYNCNT 7 |
|
|
108 | linux TCP_LINGER2 8 |
|
|
109 | linux TCP_DEFER_ACCEPT 9 |
|
|
110 | linux TCP_WINDOW_CLAMP 10 |
|
|
111 | linux TCP_INFO 11 |
|
|
112 | linux TCP_QUICKACK 12 |
|
|
113 | linux TCP_CONGESTION 13 |
|
|
114 | linux TCP_MD5SIG 14 |
|
|
115 | netbsd TCP_MAXSEG 2 |
|
|
116 | netbsd TCP_KEEPIDLE 3 |
|
|
117 | netbsd TCP_NOPUSH 4 |
|
|
118 | netbsd TCP_KEEPINTVL 5 |
|
|
119 | netbsd TCP_KEEPCNT 6 |
|
|
120 | netbsd TCP_KEEPINIT 7 |
|
|
121 | netbsd TCP_NOOPT 8 |
|
|
122 | netbsd TCP_MD5SIG 0x10 |
|
|
123 | netbsd TCP_CONGESTION 0x20 |
|
|
124 | cygwin TCP_MAXSEG 0x02 |
|
|
125 | cygwin TCP_NOPUSH 0x04 |
|
|
126 | cygwin TCP_NOOPT 0x08 |
|
|
127 | freebsd TCP_MAXSEG 0x02 |
|
|
128 | freebsd TCP_NOPUSH 0x04 |
|
|
129 | freebsd TCP_NOOPT 0x08 |
|
|
130 | freebsd TCP_MD5SIG 0x10 |
|
|
131 | freebsd TCP_INFO 0x20 |
|
|
132 | freebsd TCP_CONGESTION 0x40 |
|
|
133 | solaris TCP_CORK 0x18 |
|
|
134 | solaris TCP_LINGER2 0x1C |
|
|
135 | solaris TCP_INIT_CWND 0x15 |
|
|
136 | solaris TCP_KEEPALIVE 0x8 |
|
|
137 | solaris TCP_MAXSEG 0x02 |
|
|
138 | openbsd TCP_MAXSEG 0x02 |
|
|
139 | openbsd TCP_MD5SIG 0x04 |
|
|
140 | openbsd TCP_SACK_ENABLE 0x08 |
|
|
141 | darwin TCP_MAXSEG 0x02 |
|
|
142 | darwin TCP_NOPUSH 0x04 |
|
|
143 | darwin TCP_NOOPT 0x08 |
|
|
144 | darwin TCP_KEEPALIVE 0x10 |
|
|
145 | darwin TCP_CONNECTIONTIMEOUT 0x20 |