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.3 by root, Fri Apr 6 21:53:56 2007 UTC vs.
Revision 1.8 by root, Thu Jul 5 10:15:17 2007 UTC

17use strict; 17use strict;
18use utf8; 18use utf8;
19 19
20use Carp (); 20use Carp ();
21use AnyEvent (); 21use AnyEvent ();
22use Storable (); # finally 22use Storable ();
23 23
24use CFPlus; 24use CFPlus;
25 25
26sub sync { 26sub sync {
27 # for debugging 27 # for debugging
60 60
61use strict; 61use strict;
62 62
63use Fcntl; 63use Fcntl;
64use BerkeleyDB; 64use BerkeleyDB;
65use Config;
65 66
66our $DB_HOME = "$Crossfire::VARDIR/cfplus"; 67our $DB_HOME = "$Crossfire::VARDIR/cfplus-$BerkeleyDB::db_version-$Config{archname}";
67our $DB_ENV; 68our $DB_ENV;
68our $DB_STATE; 69our $DB_STATE;
69our %DB_TABLE; 70our %DB_TABLE;
70 71
71sub open_db { 72sub open_db {
102 -Flags => DB_CREATE | DB_UPGRADE, 103 -Flags => DB_CREATE | DB_UPGRADE,
103 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 104 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
104 } 105 }
105} 106}
106 107
107our $SYNC_INTERVAL = 6; 108our $SYNC_INTERVAL = 60;
108 109
109our %CB; 110our %CB;
110our $FH; 111our $FH;
111our $ID = "aaa0"; 112our $ID = "aaa0";
112our ($fh_r_watcher, $fh_w_watcher); 113our ($fh_r_watcher, $fh_w_watcher);
179} 180}
180 181
181sub do_get { 182sub do_get {
182 my ($db, $key) = @_; 183 my ($db, $key) = @_;
183 184
185 utf8::downgrade $key;
184 my $data; 186 my $data;
185 (table $db)->db_get ($key, $data) == 0 187 (table $db)->db_get ($key, $data) == 0
186 ? $data 188 ? $data
187 : () 189 : ()
188} 190}
189 191
190sub do_put { 192sub do_put {
191 my ($db, $key, $data) = @_; 193 my ($db, $key, $data) = @_;
192 194
195 utf8::downgrade $key;
196 utf8::downgrade $data;
193 (table $db)->db_put ($key => $data) 197 (table $db)->db_put ($key => $data)
194} 198}
195 199
196sub do_table { 200sub do_table {
197 my ($db) = @_; 201 my ($db) = @_;
245 local $SIG{__DIE__}; 249 local $SIG{__DIE__};
246 eval { 250 eval {
247 close $FH; 251 close $FH;
248 252
249 unless (eval { open_db }) { 253 unless (eval { open_db }) {
250 File::Path::rmtree $DB_HOME; 254 eval { File::Path::rmtree $DB_HOME };
251 open_db; 255 open_db;
252 } 256 }
253 257
254 while () { 258 while () {
255 4 == read $fh, my $len, 4 259 4 == read $fh, my $len, 4
289 $fh_r_watcher = AnyEvent->io (fh => $FH, poll => 'r', cb => \&fh_read); 293 $fh_r_watcher = AnyEvent->io (fh => $FH, poll => 'r', cb => \&fh_read);
290 294
291 sync_tick; 295 sync_tick;
292} 296}
293 297
298sub stop {
299 close $FH;
300}
301
2941; 3021;
295 303
296=back 304=back
297 305
298=head1 AUTHOR 306=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines