--- AnyEvent/constants.pl.PL 2010/10/11 03:41:39 1.6 +++ AnyEvent/constants.pl.PL 2012/03/27 23:47:57 1.11 @@ -2,34 +2,58 @@ # this file is unfortunately only executed at Makefile.PL time -use Socket; +use Config; + +# when built as part of perl, these are not available +BEGIN { eval "use Socket ()" } +BEGIN { eval "use Fcntl ()" } +BEGIN { eval "use POSIX ()" } open my $fh, ">lib/AnyEvent/constants.pl" or die "lib/AnyEvent/constants.pl: $_[0]\n"; my $oldstdout = select $fh; +print "# automatically generated from constants.pl.PL for perl $] built for $Config{archname}\n"; + sub i($$) { - print "sub $_[0] () { ", $_[1]*1, " }\n"; + print "sub $_[0](){", $_[1]*1, "}\n"; } sub n($$) { - print "sub $_[0] () { ", (defined $_[1] ? $_[1]*1 : "undef"), " }\n"; + print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n"; } print "package AnyEvent;\n"; our $WIN32 = $^O =~ /mswin32/i; +# used a lot i CYGWIN => $^O =~ /cygwin/i; i WIN32 => $WIN32; -use Fcntl (); +# add these purely to avoid loading Fcntl, which is slow and bloated. + +i F_SETFD => eval { Fcntl::F_SETFD() } || 2; +i F_SETFL => eval { Fcntl::F_SETFL() } || 4; +i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() } || 04000; +i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() } || 1; + +print "package AnyEvent::Base;\n"; -i F_SETFL => eval { Fcntl::F_SETFL() }; -i F_SETFD => eval { Fcntl::F_SETFD() }; -i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() }; -i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() }; +# add these purely to avoid loading POSIX, which is slow and bloated. + +i WNOHANG => eval { POSIX::WNOHANG() } || 1; + +print "package AnyEvent::IO;\n"; + +i O_RDONLY => eval { Fcntl::O_RDONLY() } || 0; +i O_WRONLY => eval { Fcntl::O_WRONLY() } || 1; +i O_RDWR => eval { Fcntl::O_RDWR () } || 2; +i O_CREAT => eval { Fcntl::O_CREAT () } || 64; +i O_EXCL => eval { Fcntl::O_EXCL () } || 128; +i O_TRUNC => eval { Fcntl::O_TRUNC () } || 512; +i O_APPEND => eval { Fcntl::O_APPEND() } || 1024; print "package AnyEvent::Util;\n"; @@ -47,17 +71,18 @@ my $af_inet6; -$af_inet6 ||= eval { Socket::AF_INET6 () }; -$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; +$af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be +$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ... -# uhoh +# ... or isn't, because nobody has it installed $af_inet6 ||= 10 if $^O =~ /linux/; $af_inet6 ||= 23 if $^O =~ /cygwin/i; $af_inet6 ||= 23 if AnyEvent::WIN32; $af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/; $af_inet6 ||= 28 if $^O =~ /freebsd/; -#TODO: WSAxxx, EDOM/ESPIPE +#TODO: EDOM/ESPIPE +#TODO: maybe move socket stuff to Socket::? i _AF_INET6 => $af_inet6; #i AF_UNIX => Socket::AF_UNIX (); @@ -69,6 +94,8 @@ #i SO_OOBINLINE => Socket::SO_OOBINLINE (); #i IPPROTO_TCP => Socket::IPPROTO_TCP (); +print "package AnyEvent::Socket;\n"; + # more hardcoded os-specific constants - none # of these are available via any known module, but we # are forward-looking and try Socket:: anyways.