ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/constants.pl.PL
(Generate patch)

Comparing AnyEvent/constants.pl.PL (file contents):
Revision 1.6 by root, Mon Oct 11 03:41:39 2010 UTC vs.
Revision 1.11 by root, Tue Mar 27 23:47:57 2012 UTC

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 4
5use Socket; 5use Config;
6
7# when built as part of perl, these are not available
8BEGIN { eval "use Socket ()" }
9BEGIN { eval "use Fcntl ()" }
10BEGIN { eval "use POSIX ()" }
6 11
7open my $fh, ">lib/AnyEvent/constants.pl" 12open my $fh, ">lib/AnyEvent/constants.pl"
8 or die "lib/AnyEvent/constants.pl: $_[0]\n"; 13 or die "lib/AnyEvent/constants.pl: $_[0]\n";
9 14
10my $oldstdout = select $fh; 15my $oldstdout = select $fh;
11 16
17print "# automatically generated from constants.pl.PL for perl $] built for $Config{archname}\n";
18
12sub i($$) { 19sub i($$) {
13 print "sub $_[0] () { ", $_[1]*1, " }\n"; 20 print "sub $_[0](){", $_[1]*1, "}\n";
14} 21}
15 22
16sub n($$) { 23sub n($$) {
17 print "sub $_[0] () { ", (defined $_[1] ? $_[1]*1 : "undef"), " }\n"; 24 print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n";
18} 25}
19 26
20print "package AnyEvent;\n"; 27print "package AnyEvent;\n";
21 28
22our $WIN32 = $^O =~ /mswin32/i; 29our $WIN32 = $^O =~ /mswin32/i;
23 30
31# used a lot
24i CYGWIN => $^O =~ /cygwin/i; 32i CYGWIN => $^O =~ /cygwin/i;
25i WIN32 => $WIN32; 33i WIN32 => $WIN32;
26 34
27use Fcntl (); 35# add these purely to avoid loading Fcntl, which is slow and bloated.
28 36
29i F_SETFL => eval { Fcntl::F_SETFL() };
30i F_SETFD => eval { Fcntl::F_SETFD() }; 37i F_SETFD => eval { Fcntl::F_SETFD() } || 2;
38i F_SETFL => eval { Fcntl::F_SETFL() } || 4;
31i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() }; 39i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() } || 04000;
32i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() }; 40i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() } || 1;
41
42print "package AnyEvent::Base;\n";
43
44# add these purely to avoid loading POSIX, which is slow and bloated.
45
46i WNOHANG => eval { POSIX::WNOHANG() } || 1;
47
48print "package AnyEvent::IO;\n";
49
50i O_RDONLY => eval { Fcntl::O_RDONLY() } || 0;
51i O_WRONLY => eval { Fcntl::O_WRONLY() } || 1;
52i O_RDWR => eval { Fcntl::O_RDWR () } || 2;
53i O_CREAT => eval { Fcntl::O_CREAT () } || 64;
54i O_EXCL => eval { Fcntl::O_EXCL () } || 128;
55i O_TRUNC => eval { Fcntl::O_TRUNC () } || 512;
56i O_APPEND => eval { Fcntl::O_APPEND() } || 1024;
33 57
34print "package AnyEvent::Util;\n"; 58print "package AnyEvent::Util;\n";
35 59
36# broken windows perls use undocumented error codes... 60# broken windows perls use undocumented error codes...
37if ($WIN32) { 61if ($WIN32) {
45 i WSAEINPROGRESS => -1e99; 69 i WSAEINPROGRESS => -1e99;
46} 70}
47 71
48my $af_inet6; 72my $af_inet6;
49 73
50$af_inet6 ||= eval { Socket::AF_INET6 () }; 74$af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be
51$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; 75$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ...
52 76
53# uhoh 77# ... or isn't, because nobody has it installed
54$af_inet6 ||= 10 if $^O =~ /linux/; 78$af_inet6 ||= 10 if $^O =~ /linux/;
55$af_inet6 ||= 23 if $^O =~ /cygwin/i; 79$af_inet6 ||= 23 if $^O =~ /cygwin/i;
56$af_inet6 ||= 23 if AnyEvent::WIN32; 80$af_inet6 ||= 23 if AnyEvent::WIN32;
57$af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/; 81$af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/;
58$af_inet6 ||= 28 if $^O =~ /freebsd/; 82$af_inet6 ||= 28 if $^O =~ /freebsd/;
59 83
60#TODO: WSAxxx, EDOM/ESPIPE 84#TODO: EDOM/ESPIPE
85#TODO: maybe move socket stuff to Socket::?
61 86
62i _AF_INET6 => $af_inet6; 87i _AF_INET6 => $af_inet6;
63#i AF_UNIX => Socket::AF_UNIX (); 88#i AF_UNIX => Socket::AF_UNIX ();
64#i SOCK_STREAM => Socket::SOCK_STREAM (); 89#i SOCK_STREAM => Socket::SOCK_STREAM ();
65#i SOCK_DGRAM => Socket::SOCK_DGRAM (); 90#i SOCK_DGRAM => Socket::SOCK_DGRAM ();
66#i SOL_SOCKET => Socket::SOL_SOCKET (); 91#i SOL_SOCKET => Socket::SOL_SOCKET ();
67#i SO_REUSEADDR => Socket::SO_REUSEADDR (); 92#i SO_REUSEADDR => Socket::SO_REUSEADDR ();
68#i SO_KEEPALIVE => Socket::SO_KEEPALIVE (); 93#i SO_KEEPALIVE => Socket::SO_KEEPALIVE ();
69#i SO_OOBINLINE => Socket::SO_OOBINLINE (); 94#i SO_OOBINLINE => Socket::SO_OOBINLINE ();
70#i IPPROTO_TCP => Socket::IPPROTO_TCP (); 95#i IPPROTO_TCP => Socket::IPPROTO_TCP ();
96
97print "package AnyEvent::Socket;\n";
71 98
72# more hardcoded os-specific constants - none 99# more hardcoded os-specific constants - none
73# of these are available via any known module, but we 100# of these are available via any known module, but we
74# are forward-looking and try Socket:: anyways. 101# are forward-looking and try Socket:: anyways.
75my %const; 102my %const;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines