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.6 by root, Mon Apr 16 21:06:37 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
102 -Flags => DB_CREATE | DB_UPGRADE, 102 -Flags => DB_CREATE | DB_UPGRADE,
103 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 103 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
104 } 104 }
105} 105}
106 106
107our $SYNC_INTERVAL = 6; 107our $SYNC_INTERVAL = 60;
108 108
109our %CB; 109our %CB;
110our $FH; 110our $FH;
111our $ID = "aaa0"; 111our $ID = "aaa0";
112our ($fh_r_watcher, $fh_w_watcher); 112our ($fh_r_watcher, $fh_w_watcher);
179} 179}
180 180
181sub do_get { 181sub do_get {
182 my ($db, $key) = @_; 182 my ($db, $key) = @_;
183 183
184 utf8::downgrade $key;
184 my $data; 185 my $data;
185 (table $db)->db_get ($key, $data) == 0 186 (table $db)->db_get ($key, $data) == 0
186 ? $data 187 ? $data
187 : () 188 : ()
188} 189}
189 190
190sub do_put { 191sub do_put {
191 my ($db, $key, $data) = @_; 192 my ($db, $key, $data) = @_;
192 193
194 utf8::downgrade $key;
195 utf8::downgrade $data;
193 (table $db)->db_put ($key => $data) 196 (table $db)->db_put ($key => $data)
194} 197}
195 198
196sub do_table { 199sub do_table {
197 my ($db) = @_; 200 my ($db) = @_;
245 local $SIG{__DIE__}; 248 local $SIG{__DIE__};
246 eval { 249 eval {
247 close $FH; 250 close $FH;
248 251
249 unless (eval { open_db }) { 252 unless (eval { open_db }) {
250 File::Path::rmtree $DB_HOME; 253 eval { File::Path::rmtree $DB_HOME };
251 open_db; 254 open_db;
252 } 255 }
253 256
254 while () { 257 while () {
255 4 == read $fh, my $len, 4 258 4 == read $fh, my $len, 4
289 $fh_r_watcher = AnyEvent->io (fh => $FH, poll => 'r', cb => \&fh_read); 292 $fh_r_watcher = AnyEvent->io (fh => $FH, poll => 'r', cb => \&fh_read);
290 293
291 sync_tick; 294 sync_tick;
292} 295}
293 296
297sub stop {
298 close $FH;
299}
300
2941; 3011;
295 302
296=back 303=back
297 304
298=head1 AUTHOR 305=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines