ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/DB.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/DB.pm (file contents):
Revision 1.27 by root, Wed Dec 26 18:20:46 2007 UTC vs.
Revision 1.28 by root, Wed Dec 26 20:46:39 2007 UTC

1=head1 NAME 1=head1 NAME
2 2
3CFPlus::DB - async. database and filesystem access for cfplus 3dc::DB - async. database and filesystem access for cfplus
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use CFPlus::DB; 7 use dc::DB;
8 8
9=head1 DESCRIPTION 9=head1 DESCRIPTION
10 10
11=over 4 11=over 4
12 12
13=cut 13=cut
14 14
15package CFPlus::DB; 15package dc::DB;
16 16
17use strict; 17use strict;
18use utf8; 18use utf8;
19 19
20use Carp (); 20use Carp ();
21use Storable (); 21use Storable ();
22use Config; 22use Config;
23use BDB; 23use BDB;
24 24
25use CFPlus; 25use dc;
26 26
27our $DBDIR = "cfplus-" . BDB::VERSION . "-$Config{archname}"; 27our $DBDIR = "cfplus-" . BDB::VERSION . "-$Config{archname}";
28our $DB_HOME = "$Deliantra::VARDIR/$DBDIR"; 28our $DB_HOME = "$Deliantra::VARDIR/$DBDIR";
29 29
30if (!-e $DB_HOME and -e "$Deliantra::OLDDIR/$DBDIR") { 30if (!-e $DB_HOME and -e "$Deliantra::OLDDIR/$DBDIR") {
175 $tilemap = $_[0]; 175 $tilemap = $_[0];
176 delete $tilemap->{id}; 176 delete $tilemap->{id};
177 my %maptile = reverse %$tilemap;#d# 177 my %maptile = reverse %$tilemap;#d#
178 if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d# 178 if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d#
179 $tilemap = { };#d# 179 $tilemap = { };#d#
180 CFPlus::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d# 180 dc::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d#
181 }#d# 181 }#d#
182 }; 182 };
183 BDB::flush; 183 BDB::flush;
184 } 184 }
185 185
200 "$DB_HOME/res-data-" . unpack "H*", $_[0] 200 "$DB_HOME/res-data-" . unpack "H*", $_[0]
201} 201}
202 202
203sub sync { 203sub sync {
204 # for debugging 204 # for debugging
205 #CFPlus::DB::Server::req (sync => sub { }); 205 #dc::DB::Server::req (sync => sub { });
206 CFPlus::DB::Server::sync (); 206 dc::DB::Server::sync ();
207} 207}
208 208
209sub unlink($$) { 209sub unlink($$) {
210 CFPlus::DB::Server::req (unlink => @_); 210 dc::DB::Server::req (unlink => @_);
211} 211}
212 212
213sub read_file($$) { 213sub read_file($$) {
214 CFPlus::DB::Server::req (read_file => @_); 214 dc::DB::Server::req (read_file => @_);
215} 215}
216 216
217sub write_file($$$) { 217sub write_file($$$) {
218 CFPlus::DB::Server::req (write_file => @_); 218 dc::DB::Server::req (write_file => @_);
219} 219}
220 220
221sub prefetch_file($$$) { 221sub prefetch_file($$$) {
222 CFPlus::DB::Server::req (prefetch_file => @_); 222 dc::DB::Server::req (prefetch_file => @_);
223} 223}
224 224
225sub logprint($$$) { 225sub logprint($$$) {
226 CFPlus::DB::Server::req (logprint => @_); 226 dc::DB::Server::req (logprint => @_);
227} 227}
228 228
229package CFPlus::DB::Server; 229package dc::DB::Server;
230 230
231use strict; 231use strict;
232 232
233use EV (); 233use EV ();
234use Fcntl; 234use Fcntl;
355 355
356 print { $LOG_FH{$path} } "$ts $line\n" 356 print { $LOG_FH{$path} } "$ts $line\n"
357} 357}
358 358
359sub run { 359sub run {
360 ($FH, my $fh) = CFPlus::socketpipe; 360 ($FH, my $fh) = dc::socketpipe;
361 361
362 my $oldfh = select $FH; $| = 1; select $oldfh; 362 my $oldfh = select $FH; $| = 1; select $oldfh;
363 my $oldfh = select $fh; $| = 1; select $oldfh; 363 my $oldfh = select $fh; $| = 1; select $oldfh;
364 364
365 my $pid = fork; 365 my $pid = fork;
379 or die "unexpected eof while reading request"; 379 or die "unexpected eof while reading request";
380 380
381 $req = Storable::thaw $req; 381 $req = Storable::thaw $req;
382 382
383 my ($id, $type, @args) = @$req; 383 my ($id, $type, @args) = @$req;
384 my $cb = CFPlus::DB::Server->can ("do_$type") 384 my $cb = dc::DB::Server->can ("do_$type")
385 or die "$type: unknown database request type\n"; 385 or die "$type: unknown database request type\n";
386 my $res = pack "N/a*", Storable::freeze [$id, $cb->(@args)]; 386 my $res = pack "N/a*", Storable::freeze [$id, $cb->(@args)];
387 (syswrite $fh, $res) == length $res 387 (syswrite $fh, $res) == length $res
388 or die "DB::write: $!"; 388 or die "DB::write: $!";
389 } 389 }
396 }; 396 };
397 397
398 warn $error 398 warn $error
399 if $error; 399 if $error;
400 400
401 CFPlus::_exit 0; 401 dc::_exit 0;
402 } 402 }
403 403
404 close $fh; 404 close $fh;
405 CFPlus::fh_nonblocking $FH, 1; 405 dc::fh_nonblocking $FH, 1;
406 406
407 $CB{die} = sub { die shift }; 407 $CB{die} = sub { die shift };
408 408
409 $fh_r_watcher = EV::io $FH, EV::READ , \&fh_read; 409 $fh_r_watcher = EV::io $FH, EV::READ , \&fh_read;
410 $fh_w_watcher = EV::io $FH, EV::WRITE, \&fh_write; 410 $fh_w_watcher = EV::io $FH, EV::WRITE, \&fh_write;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines