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