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.14 by root, Wed Aug 21 08:40:28 2013 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; 5my ($fh, $oldstdout);
6 6
7BEGIN {
7open my $fh, ">lib/AnyEvent/constants.pl" 8 open $fh, ">lib/AnyEvent/constants.pl"
8 or die "lib/AnyEvent/constants.pl: $_[0]\n"; 9 or die "lib/AnyEvent/constants.pl: $!\n";
9 10
10my $oldstdout = select $fh; 11 $oldstdout = select $fh;
12
13 print "# automatically generated from constants.pl.PL\n";
14}
15
16{
17 # from common::sense 3.7
18 use strict qw(vars subs);
19 no warnings;
20 use warnings qw(FATAL closed threads internal debugging pack malloc portable prototype
21 inplace io pipe unpack deprecated glob digit printf
22 layer reserved taint closure semicolon);
23 no warnings qw(exec newline unopened);
24
25 BEGIN {
26 print "sub AnyEvent::common_sense {\n";
27 printf " local \$^W;\n";
28 printf " \${^WARNING_BITS} ^= \${^WARNING_BITS} ^ \"%s\";\n",
29 join "", map "\\x$_", unpack "(H2)*", ${^WARNING_BITS};
30 # use strict, use utf8;
31 printf " \$^H |= 0x%x;\n", $^H;
32 print "}\n";
33 }
34}
35
36use Config;
37
38print "# generated for perl $] built for $Config{archname}\n";
39
40# when built as part of perl, these are not available
41BEGIN { eval "use Socket ()" }
42BEGIN { eval "use Fcntl ()" }
43BEGIN { eval "use POSIX ()" }
11 44
12sub i($$) { 45sub i($$) {
13 print "sub $_[0] () { ", $_[1]*1, " }\n"; 46 print "sub $_[0](){", $_[1]*1, "}\n";
14} 47}
15 48
16sub n($$) { 49sub n($$) {
17 print "sub $_[0] () { ", (defined $_[1] ? $_[1]*1 : "undef"), " }\n"; 50 print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n";
18} 51}
19 52
20print "package AnyEvent;\n"; 53print "package AnyEvent;\n";
21 54
22our $WIN32 = $^O =~ /mswin32/i; 55our $WIN32 = $^O =~ /mswin32/i;
23 56
57# used a lot
24i CYGWIN => $^O =~ /cygwin/i; 58i CYGWIN => $^O =~ /cygwin/i;
25i WIN32 => $WIN32; 59i WIN32 => $WIN32;
26 60
27use Fcntl (); 61# add these purely to avoid loading Fcntl, which is slow and bloated.
28 62
29i F_SETFL => eval { Fcntl::F_SETFL() };
30i F_SETFD => eval { Fcntl::F_SETFD() }; 63i F_SETFD => eval { Fcntl::F_SETFD() } || 2;
64i F_SETFL => eval { Fcntl::F_SETFL() } || 4;
31i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() }; 65i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() } || 04000;
32i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() }; 66i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() } || 1;
67
68print "package AnyEvent::Base;\n";
69
70# add these purely to avoid loading POSIX, which is slow and bloated.
71
72i WNOHANG => eval { POSIX::WNOHANG() } || 1;
73
74print "package AnyEvent::IO;\n";
75
76i O_RDONLY => eval { Fcntl::O_RDONLY() } || 0;
77i O_WRONLY => eval { Fcntl::O_WRONLY() } || 1;
78i O_RDWR => eval { Fcntl::O_RDWR () } || 2;
79i O_CREAT => eval { Fcntl::O_CREAT () } || 64;
80i O_EXCL => eval { Fcntl::O_EXCL () } || 128;
81i O_TRUNC => eval { Fcntl::O_TRUNC () } || 512;
82i O_APPEND => eval { Fcntl::O_APPEND() } || 1024;
33 83
34print "package AnyEvent::Util;\n"; 84print "package AnyEvent::Util;\n";
35 85
36# broken windows perls use undocumented error codes... 86# broken windows perls use undocumented error codes...
37if ($WIN32) { 87if ($WIN32) {
45 i WSAEINPROGRESS => -1e99; 95 i WSAEINPROGRESS => -1e99;
46} 96}
47 97
48my $af_inet6; 98my $af_inet6;
49 99
50$af_inet6 ||= eval { Socket::AF_INET6 () }; 100$af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be
51$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; 101$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ...
52 102
53# uhoh 103# ... or isn't, because nobody has it installed
54$af_inet6 ||= 10 if $^O =~ /linux/; 104$af_inet6 ||= 10 if $^O =~ /linux/;
55$af_inet6 ||= 23 if $^O =~ /cygwin/i; 105$af_inet6 ||= 23 if $^O =~ /cygwin/i;
56$af_inet6 ||= 23 if AnyEvent::WIN32; 106$af_inet6 ||= 23 if AnyEvent::WIN32;
57$af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/; 107$af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/;
58$af_inet6 ||= 28 if $^O =~ /freebsd/; 108$af_inet6 ||= 28 if $^O =~ /freebsd/;
59 109
60#TODO: WSAxxx, EDOM/ESPIPE 110#TODO: EDOM/ESPIPE
111#TODO: maybe move socket stuff to Socket::?
61 112
62i _AF_INET6 => $af_inet6; 113i _AF_INET6 => $af_inet6;
63#i AF_UNIX => Socket::AF_UNIX (); 114#i AF_UNIX => Socket::AF_UNIX ();
64#i SOCK_STREAM => Socket::SOCK_STREAM (); 115#i SOCK_STREAM => Socket::SOCK_STREAM ();
65#i SOCK_DGRAM => Socket::SOCK_DGRAM (); 116#i SOCK_DGRAM => Socket::SOCK_DGRAM ();
66#i SOL_SOCKET => Socket::SOL_SOCKET (); 117#i SOL_SOCKET => Socket::SOL_SOCKET ();
67#i SO_REUSEADDR => Socket::SO_REUSEADDR (); 118#i SO_REUSEADDR => Socket::SO_REUSEADDR ();
68#i SO_KEEPALIVE => Socket::SO_KEEPALIVE (); 119#i SO_KEEPALIVE => Socket::SO_KEEPALIVE ();
69#i SO_OOBINLINE => Socket::SO_OOBINLINE (); 120#i SO_OOBINLINE => Socket::SO_OOBINLINE ();
70#i IPPROTO_TCP => Socket::IPPROTO_TCP (); 121#i IPPROTO_TCP => Socket::IPPROTO_TCP ();
122
123print "package AnyEvent::Socket;\n";
71 124
72# more hardcoded os-specific constants - none 125# more hardcoded os-specific constants - none
73# of these are available via any known module, but we 126# of these are available via any known module, but we
74# are forward-looking and try Socket:: anyways. 127# are forward-looking and try Socket:: anyways.
75my %const; 128my %const;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines