ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/constants.pl.PL
Revision: 1.6
Committed: Mon Oct 11 03:41:39 2010 UTC (13 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.5: +75 -3 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 Socket;
6
7 open my $fh, ">lib/AnyEvent/constants.pl"
8 or die "lib/AnyEvent/constants.pl: $_[0]\n";
9
10 my $oldstdout = select $fh;
11
12 sub i($$) {
13 print "sub $_[0] () { ", $_[1]*1, " }\n";
14 }
15
16 sub n($$) {
17 print "sub $_[0] () { ", (defined $_[1] ? $_[1]*1 : "undef"), " }\n";
18 }
19
20 print "package AnyEvent;\n";
21
22 our $WIN32 = $^O =~ /mswin32/i;
23
24 i CYGWIN => $^O =~ /cygwin/i;
25 i WIN32 => $WIN32;
26
27 use Fcntl ();
28
29 i F_SETFL => eval { Fcntl::F_SETFL() };
30 i F_SETFD => eval { Fcntl::F_SETFD() };
31 i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() };
32 i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() };
33
34 print "package AnyEvent::Util;\n";
35
36 # broken windows perls use undocumented error codes...
37 if ($WIN32) {
38 i WSAEINVAL => 10022;
39 i WSAEWOULDBLOCK => 10035;
40 i WSAEINPROGRESS => 10036;
41 } else {
42 # these should never match any errno value
43 i WSAEINVAL => -1e99;
44 i WSAEWOULDBLOCK => -1e99;
45 i WSAEINPROGRESS => -1e99;
46 }
47
48 my $af_inet6;
49
50 $af_inet6 ||= eval { Socket::AF_INET6 () };
51 $af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() };
52
53 # uhoh
54 $af_inet6 ||= 10 if $^O =~ /linux/;
55 $af_inet6 ||= 23 if $^O =~ /cygwin/i;
56 $af_inet6 ||= 23 if AnyEvent::WIN32;
57 $af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/;
58 $af_inet6 ||= 28 if $^O =~ /freebsd/;
59
60 #TODO: WSAxxx, EDOM/ESPIPE
61
62 i _AF_INET6 => $af_inet6;
63 #i AF_UNIX => Socket::AF_UNIX ();
64 #i SOCK_STREAM => Socket::SOCK_STREAM ();
65 #i SOCK_DGRAM => Socket::SOCK_DGRAM ();
66 #i SOL_SOCKET => Socket::SOL_SOCKET ();
67 #i SO_REUSEADDR => Socket::SO_REUSEADDR ();
68 #i SO_KEEPALIVE => Socket::SO_KEEPALIVE ();
69 #i SO_OOBINLINE => Socket::SO_OOBINLINE ();
70 #i IPPROTO_TCP => Socket::IPPROTO_TCP ();
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
94 print "1;\n";
95
96 close $fh;
97 select $oldstdout;
98
99 1
100
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