… | |
… | |
10 | |
10 | |
11 | =over 4 |
11 | =over 4 |
12 | |
12 | |
13 | =cut |
13 | =cut |
14 | |
14 | |
15 | package Deliantra::Client; # work around CPAN breakage |
|
|
16 | package App::Deliantra; # try to reserve namespace |
|
|
17 | package DC; |
15 | package DC; |
18 | |
16 | |
19 | use Carp (); |
17 | use Carp (); |
20 | |
18 | |
21 | our $VERSION; |
19 | our $VERSION; |
22 | |
20 | |
23 | BEGIN { |
21 | BEGIN { |
24 | $VERSION = '0.9975'; |
22 | $VERSION = '2.02'; |
25 | |
23 | |
26 | use XSLoader; |
24 | use XSLoader; |
27 | XSLoader::load "Deliantra::Client", $VERSION; |
25 | XSLoader::load "Deliantra::Client", $VERSION; |
28 | } |
26 | } |
29 | |
27 | |
30 | use utf8; |
28 | use utf8; |
31 | use strict qw(vars subs); |
29 | use strict qw(vars subs); |
32 | |
30 | |
|
|
31 | use Socket (); |
33 | use AnyEvent (); |
32 | use AnyEvent (); |
|
|
33 | use AnyEvent::Util (); |
34 | use Pod::POM (); |
34 | use Pod::POM (); |
35 | use File::Path (); |
35 | use File::Path (); |
36 | use Storable (); # finally |
36 | use Storable (); # finally |
37 | use Fcntl (); |
37 | use Fcntl (); |
38 | use JSON::XS qw(encode_json decode_json); |
38 | use JSON::XS qw(encode_json decode_json); |
… | |
… | |
69 | s/</</g; |
69 | s/</</g; |
70 | |
70 | |
71 | $_ |
71 | $_ |
72 | } |
72 | } |
73 | |
73 | |
74 | sub socketpipe() { |
|
|
75 | socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC |
|
|
76 | or die "cannot establish bidirectional pipe: $!\n"; |
|
|
77 | |
|
|
78 | ($fh1, $fh2) |
|
|
79 | } |
|
|
80 | |
|
|
81 | sub background(&;&) { |
74 | sub background(&;&) { |
82 | my ($bg, $cb) = @_; |
75 | my ($bg, $cb) = @_; |
83 | |
76 | |
84 | my ($fh_r, $fh_w) = DC::socketpipe; |
77 | my ($fh_r, $fh_w) = AnyEvent::Util::portable_socketpair |
|
|
78 | or die "unable to create background socketpair: $!"; |
85 | |
79 | |
86 | my $pid = fork; |
80 | my $pid = fork; |
87 | |
81 | |
88 | if (defined $pid && !$pid) { |
82 | if (defined $pid && !$pid) { |
89 | local $SIG{__DIE__}; |
83 | local $SIG{__DIE__}; |