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.2 by root, Fri Apr 6 08:09:43 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
24use CFPlus;
23 25
24sub sync { 26sub sync {
25 # for debugging 27 # for debugging
26 #CFPlus::DB::Server::req (sync => sub { }); 28 #CFPlus::DB::Server::req (sync => sub { });
27 CFPlus::DB::Server::sync (); 29 CFPlus::DB::Server::sync ();
100 -Flags => DB_CREATE | DB_UPGRADE, 102 -Flags => DB_CREATE | DB_UPGRADE,
101 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 103 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
102 } 104 }
103} 105}
104 106
105our $SYNC_INTERVAL = 6; 107our $SYNC_INTERVAL = 60;
106 108
107our %CB; 109our %CB;
108our $FH; 110our $FH;
109our $ID = "aaa0"; 111our $ID = "aaa0";
110our ($fh_r_watcher, $fh_w_watcher); 112our ($fh_r_watcher, $fh_w_watcher);
177} 179}
178 180
179sub do_get { 181sub do_get {
180 my ($db, $key) = @_; 182 my ($db, $key) = @_;
181 183
184 utf8::downgrade $key;
182 my $data; 185 my $data;
183 (table $db)->db_get ($key, $data) == 0 186 (table $db)->db_get ($key, $data) == 0
184 ? $data 187 ? $data
185 : () 188 : ()
186} 189}
187 190
188sub do_put { 191sub do_put {
189 my ($db, $key, $data) = @_; 192 my ($db, $key, $data) = @_;
190 193
194 utf8::downgrade $key;
195 utf8::downgrade $data;
191 (table $db)->db_put ($key => $data) 196 (table $db)->db_put ($key => $data)
192} 197}
193 198
194sub do_table { 199sub do_table {
195 my ($db) = @_; 200 my ($db) = @_;
243 local $SIG{__DIE__}; 248 local $SIG{__DIE__};
244 eval { 249 eval {
245 close $FH; 250 close $FH;
246 251
247 unless (eval { open_db }) { 252 unless (eval { open_db }) {
248 File::Path::rmtree $DB_HOME; 253 eval { File::Path::rmtree $DB_HOME };
249 open_db; 254 open_db;
250 } 255 }
251 256
252 while () { 257 while () {
253 4 == read $fh, my $len, 4 258 4 == read $fh, my $len, 4
278 283
279 CFPlus::_exit 0; 284 CFPlus::_exit 0;
280 } 285 }
281 286
282 close $fh; 287 close $fh;
283 fcntl $FH, F_SETFL, O_NONBLOCK; 288 CFPlus::fh_nonblocking $FH, 1;
284 289
285 $CB{die} = sub { die shift }; 290 $CB{die} = sub { die shift };
286 291
287 $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);
288 293
289 sync_tick; 294 sync_tick;
295}
296
297sub stop {
298 close $FH;
290} 299}
291 300
2921; 3011;
293 302
294=back 303=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines