ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.183 by root, Fri Jan 19 19:42:37 2007 UTC vs.
Revision 1.187 by root, Sat Jan 20 21:06:52 2007 UTC

349 my $runtime = cf::localdir . "/runtime"; 349 my $runtime = cf::localdir . "/runtime";
350 350
351 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 351 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644
352 or return; 352 or return;
353 353
354 my $value = $cf::RUNTIME + 90 + 10;
354 my $value = $cf::RUNTIME + 1 + 10; # 10 is the runtime save interval, for a monotonic clock 355 # 10 is the runtime save interval, for a monotonic clock
356 # 60 allows for the watchdog to kill the server.
357
355 (aio_write $fh, 0, (length $value), $value, 0) <= 0 358 (aio_write $fh, 0, (length $value), $value, 0) <= 0
356 and return; 359 and return;
357 360
358 aio_fsync $fh 361 aio_fsync $fh
359 and return; 362 and return;
1137 $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used}, 1140 $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used},
1138 (cf::region::find $rmp->{region}), $rmp->{custom} 1141 (cf::region::find $rmp->{region}), $rmp->{custom}
1139 ) 1142 )
1140} 1143}
1141 1144
1145=item cf::map->register ($regex, $prio)
1146
1147Register a handler for the map path matching the given regex at the
1148givne priority (higher is better, built-in handlers have priority 0, the
1149default).
1150
1151=cut
1152
1142sub register { 1153sub register {
1143 my (undef, $regex) = @_; 1154 my (undef, $regex, $prio) = @_;
1144 my $pkg = caller; 1155 my $pkg = caller;
1145 1156
1146 no strict; 1157 no strict;
1147 push @{"$pkg\::ISA"}, __PACKAGE__; 1158 push @{"$pkg\::ISA"}, __PACKAGE__;
1148 1159
1149 $EXT_MAP{$pkg} = qr<$regex>; 1160 $EXT_MAP{$pkg} = [$prio, qr<$regex>];
1150} 1161}
1151 1162
1152# also paths starting with '/' 1163# also paths starting with '/'
1153$EXT_MAP{"cf::map"} = qr{^(?=/)}; 1164$EXT_MAP{"cf::map"} = [0, qr{^(?=/)}];
1154 1165
1155sub thawer_merge { 1166sub thawer_merge {
1156 my ($self, $merge) = @_; 1167 my ($self, $merge) = @_;
1157 1168
1158 # we have to keep some variables in memory intact 1169 # we have to keep some variables in memory intact
1201 1212
1202 return $path if UNIVERSAL::isa $path, "cf::map"; # already a map object 1213 return $path if UNIVERSAL::isa $path, "cf::map"; # already a map object
1203 1214
1204 $path = normalise $path, $base; 1215 $path = normalise $path, $base;
1205 1216
1206 for my $pkg (keys %EXT_MAP) { 1217 for my $pkg (sort { $EXT_MAP{$b}[0] <=> $EXT_MAP{$a}[0] } keys %EXT_MAP) {
1207 if ($path =~ $EXT_MAP{$pkg}) { 1218 if ($path =~ $EXT_MAP{$pkg}[1]) {
1208 my $self = bless cf::map::new, $pkg; 1219 my $self = bless cf::map::new, $pkg;
1209 $self->{path} = $path; $self->path ($path); 1220 $self->{path} = $path; $self->path ($path);
1210 $self->init; # pass $1 etc. 1221 $self->init; # pass $1 etc.
1211 return $self; 1222 return $self;
1212 } 1223 }
1339 1350
1340 $map->load_header 1351 $map->load_header
1341 or return; 1352 or return;
1342 1353
1343 if ($map->should_reset) { 1354 if ($map->should_reset) {
1355 # doing this can freeze the server in a sync job, obviously
1344 $cf::WAIT_FOR_TICK->wait; 1356 #$cf::WAIT_FOR_TICK->wait;
1345 $map->reset; 1357 $map->reset;
1346 undef $guard; 1358 undef $guard;
1347 $map = find $path 1359 $map = find $path
1348 or return; 1360 or return;
1349 } 1361 }
1456 1468
1457 undef $MAP_PREFETCH{$path}; 1469 undef $MAP_PREFETCH{$path};
1458 $MAP_PREFETCHER ||= cf::async { 1470 $MAP_PREFETCHER ||= cf::async {
1459 while (%MAP_PREFETCH) { 1471 while (%MAP_PREFETCH) {
1460 for my $path (keys %MAP_PREFETCH) { 1472 for my $path (keys %MAP_PREFETCH) {
1461 warn "prefetching $path...\n";#d#
1462 my $map = find $path 1473 my $map = find $path
1463 or next; 1474 or next;
1464 $map->load; 1475 $map->load;
1465 1476
1466 delete $MAP_PREFETCH{$path}; 1477 delete $MAP_PREFETCH{$path};
2477 2488
2478$WRITE_RUNTIME_WATCHER = Event->timer ( 2489$WRITE_RUNTIME_WATCHER = Event->timer (
2479 data => WF_AUTOCANCEL, 2490 data => WF_AUTOCANCEL,
2480 after => 1, 2491 after => 1,
2481 interval => 10, 2492 interval => 10,
2493 prio => 6, # keep it lowest so it acts like a watchdog
2482 cb => Coro::unblock_sub { 2494 cb => Coro::unblock_sub {
2483 write_runtime 2495 write_runtime
2484 or warn "ERROR: unable to write runtime file: $!"; 2496 or warn "ERROR: unable to write runtime file: $!";
2485 }, 2497 },
2486); 2498);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines