--- deliantra/Deliantra-Client/DC.pm 2006/09/29 00:56:05 1.121 +++ deliantra/Deliantra-Client/DC.pm 2006/10/18 12:53:45 1.125 @@ -17,7 +17,7 @@ use Carp (); BEGIN { - $VERSION = '0.52'; + $VERSION = '0.53'; use XSLoader; XSLoader::load "CFPlus", $VERSION; @@ -64,6 +64,66 @@ $_ } +sub socketpipe() { + socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC + or die "cannot establish bidiretcional pipe: $!\n"; + + ($fh1, $fh2) +} + +sub background(&) { + my ($cb) = @_; + + my ($fh_r, $fh_w) = CFPlus::socketpipe; + + my $pid = fork; + + if (defined $pid && !$pid) { + local $SIG{__DIE__}; + + open STDOUT, ">&", $fh_w; + open STDERR, ">&", $fh_w; + close $fh_r; + close $fh_w; + + $| = 1; + + eval { $cb->() }; + + if ($@) { + my $msg = $@; + $msg =~ s/\n+/\n/; + warn "FATAL: $msg"; + CFPlus::_exit 1; + } + + # win32 is fucked up, of course. exit will clean stuff up, + # which destroys our database etc. _exit will exit ALL + # forked processes, because of the dreaded fork emulation. + CFPlus::_exit 0; + } + + close $fh_w; + + my $buffer; + + Event->io (fd => $fh_r, poll => 'r', cb => sub { + unless (sysread $fh_r, $buffer, 4096, length $buffer) { + $_[0]->w->cancel; + $buffer .= "done\n"; + } + + while ($buffer =~ s/^(.*)\n//) { + my $line = $1; + $line =~ s/\s+$//; + utf8::decode $line; + ::message ({ + markup => "editor($pid): " . CFPlus::asxml $line, + }); + } + }); +} + package CFPlus::Database; our @ISA = BerkeleyDB::Btree::; @@ -140,6 +200,25 @@ print $fh to_json $::CFG; } +sub http_proxy { + my @proxy = win32_proxy_info; + + if (@proxy) { + "http://" . (@proxy < 2 ? "" : @proxy < 3 ? "$proxy[1]\@" : "$proxy[1]:$proxy[2]\@") . $proxy[0] + } elsif (exists $ENV{http_proxy}) { + $ENV{http_proxy} + } else { + () + } +} + +sub set_proxy { + my $proxy = http_proxy + or return; + + $ENV{http_proxy} = $proxy; +} + our $DB_ENV; our $DB_STATE;