… | |
… | |
1176 | } |
1176 | } |
1177 | |
1177 | |
1178 | sub normalise { |
1178 | sub normalise { |
1179 | my ($path, $base) = @_; |
1179 | my ($path, $base) = @_; |
1180 | |
1180 | |
|
|
1181 | $path = "$path"; # make sure its a string |
|
|
1182 | |
1181 | # map plan: |
1183 | # map plan: |
1182 | # |
1184 | # |
1183 | # /! non-realised random map exit (special hack!) |
1185 | # /! non-realised random map exit (special hack!) |
1184 | # {... are special paths that are not being touched |
1186 | # {... are special paths that are not being touched |
1185 | # ?xxx/... are special absolute paths |
1187 | # ?xxx/... are special absolute paths |
… | |
… | |
1221 | $self->init; # pass $1 etc. |
1223 | $self->init; # pass $1 etc. |
1222 | return $self; |
1224 | return $self; |
1223 | } |
1225 | } |
1224 | } |
1226 | } |
1225 | |
1227 | |
1226 | Carp::carp "unable to resolve path '$path'."; |
1228 | Carp::carp "unable to resolve path '$path' (base '$base')."; |
1227 | () |
1229 | () |
1228 | } |
1230 | } |
1229 | |
1231 | |
1230 | sub init { |
1232 | sub init { |
1231 | my ($self) = @_; |
1233 | my ($self) = @_; |
… | |
… | |
1365 | if ($map->should_reset) { |
1367 | if ($map->should_reset) { |
1366 | # doing this can freeze the server in a sync job, obviously |
1368 | # doing this can freeze the server in a sync job, obviously |
1367 | #$cf::WAIT_FOR_TICK->wait; |
1369 | #$cf::WAIT_FOR_TICK->wait; |
1368 | $map->reset; |
1370 | $map->reset; |
1369 | undef $guard; |
1371 | undef $guard; |
1370 | $map = find $path |
1372 | return find $path; |
1371 | or return; |
|
|
1372 | } |
1373 | } |
1373 | |
1374 | |
1374 | $cf::MAP{$path} = $map |
1375 | $cf::MAP{$path} = $map |
1375 | } |
1376 | } |
1376 | } |
1377 | } |
… | |
… | |
1496 | delete $MAP_PREFETCH{$path}; |
1497 | delete $MAP_PREFETCH{$path}; |
1497 | } |
1498 | } |
1498 | } |
1499 | } |
1499 | undef $MAP_PREFETCHER; |
1500 | undef $MAP_PREFETCHER; |
1500 | }; |
1501 | }; |
|
|
1502 | $MAP_PREFETCHER->prio (6); |
1501 | |
1503 | |
1502 | () |
1504 | () |
1503 | } |
1505 | } |
1504 | |
1506 | |
1505 | sub save { |
1507 | sub save { |
… | |
… | |
2205 | sub db_sync() { |
2207 | sub db_sync() { |
2206 | db_save if $dirty; |
2208 | db_save if $dirty; |
2207 | undef $dirty; |
2209 | undef $dirty; |
2208 | } |
2210 | } |
2209 | |
2211 | |
2210 | my $idle = Event->idle (min => 10, max => 20, repeat => 0, data => WF_AUTOCANCEL, cb => sub { |
2212 | my $idle = Event->idle ( |
2211 | db_sync; |
2213 | reentrant => 0, |
|
|
2214 | min => 10, |
|
|
2215 | max => 20, |
|
|
2216 | repeat => 0, |
|
|
2217 | data => WF_AUTOCANCEL, |
|
|
2218 | cb => \&db_sync, |
2212 | }); |
2219 | ); |
2213 | |
2220 | |
2214 | sub db_dirty() { |
2221 | sub db_dirty() { |
2215 | $dirty = 1; |
2222 | $dirty = 1; |
2216 | $idle->start; |
2223 | $idle->start; |
2217 | } |
2224 | } |
… | |
… | |
2285 | |
2292 | |
2286 | # install some emergency cleanup handlers |
2293 | # install some emergency cleanup handlers |
2287 | BEGIN { |
2294 | BEGIN { |
2288 | for my $signal (qw(INT HUP TERM)) { |
2295 | for my $signal (qw(INT HUP TERM)) { |
2289 | Event->signal ( |
2296 | Event->signal ( |
|
|
2297 | reentrant => 0, |
2290 | data => WF_AUTOCANCEL, |
2298 | data => WF_AUTOCANCEL, |
2291 | signal => $signal, |
2299 | signal => $signal, |
|
|
2300 | prio => 0, |
2292 | cb => sub { |
2301 | cb => sub { |
2293 | cf::cleanup "SIG$signal"; |
2302 | cf::cleanup "SIG$signal"; |
2294 | }, |
2303 | }, |
2295 | ); |
2304 | ); |
2296 | } |
2305 | } |
2297 | } |
2306 | } |
… | |
… | |
2452 | $who->message ("reloading server."); |
2461 | $who->message ("reloading server."); |
2453 | |
2462 | |
2454 | # doing reload synchronously and two reloads happen back-to-back, |
2463 | # doing reload synchronously and two reloads happen back-to-back, |
2455 | # coro crashes during coro_state_free->destroy here. |
2464 | # coro crashes during coro_state_free->destroy here. |
2456 | |
2465 | |
2457 | $RELOAD_WATCHER ||= Event->timer (after => 0, data => WF_AUTOCANCEL, cb => sub { |
2466 | $RELOAD_WATCHER ||= Event->timer ( |
|
|
2467 | reentrant => 0, |
|
|
2468 | after => 0, |
|
|
2469 | data => WF_AUTOCANCEL, |
|
|
2470 | cb => sub { |
2458 | reload; |
2471 | reload; |
2459 | undef $RELOAD_WATCHER; |
2472 | undef $RELOAD_WATCHER; |
|
|
2473 | }, |
2460 | }); |
2474 | ); |
2461 | } |
2475 | } |
2462 | }; |
2476 | }; |
2463 | |
2477 | |
2464 | unshift @INC, $LIBDIR; |
2478 | unshift @INC, $LIBDIR; |
2465 | |
2479 | |
… | |
… | |
2485 | $NEXT_TICK += $TICK; |
2499 | $NEXT_TICK += $TICK; |
2486 | |
2500 | |
2487 | $WAIT_FOR_TICK->broadcast; |
2501 | $WAIT_FOR_TICK->broadcast; |
2488 | $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; |
2502 | $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; |
2489 | |
2503 | |
|
|
2504 | Event::sweep; |
|
|
2505 | Coro::cede_notself; |
|
|
2506 | |
|
|
2507 | # my $AFTER = Event::time; |
|
|
2508 | # warn $AFTER - $NOW;#d# |
|
|
2509 | |
2490 | # if we are delayed by four ticks or more, skip them all |
2510 | # if we are delayed by four ticks or more, skip them all |
2491 | $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4; |
2511 | $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4; |
2492 | |
2512 | |
2493 | $TICK_WATCHER->at ($NEXT_TICK); |
2513 | $TICK_WATCHER->at ($NEXT_TICK); |
2494 | $TICK_WATCHER->start; |
2514 | $TICK_WATCHER->start; |
2495 | }, |
2515 | }, |
2496 | ); |
2516 | ); |
2497 | |
2517 | |
2498 | IO::AIO::max_poll_time $TICK * 0.2; |
2518 | IO::AIO::max_poll_time $TICK * 0.1; |
2499 | |
2519 | |
|
|
2520 | undef $Coro::AIO::WATCHER; |
2500 | $AIO_POLL_WATCHER = Event->io ( |
2521 | $AIO_POLL_WATCHER = Event->io ( |
|
|
2522 | reentrant => 0, |
2501 | fd => IO::AIO::poll_fileno, |
2523 | fd => IO::AIO::poll_fileno, |
2502 | poll => 'r', |
2524 | poll => 'r', |
2503 | prio => 5, |
2525 | prio => 6, |
2504 | data => WF_AUTOCANCEL, |
2526 | data => WF_AUTOCANCEL, |
2505 | cb => \&IO::AIO::poll_cb, |
2527 | cb => \&IO::AIO::poll_cb, |
2506 | ); |
2528 | ); |
2507 | |
2529 | |
2508 | $WRITE_RUNTIME_WATCHER = Event->timer ( |
2530 | $WRITE_RUNTIME_WATCHER = Event->timer ( |
|
|
2531 | reentrant => 0, |
2509 | data => WF_AUTOCANCEL, |
2532 | data => WF_AUTOCANCEL, |
2510 | after => 1, |
2533 | after => 1, |
2511 | interval => 10, |
2534 | interval => 10, |
2512 | prio => 6, # keep it lowest so it acts like a watchdog |
2535 | prio => 6, # keep it lowest so it acts like a watchdog |
2513 | cb => Coro::unblock_sub { |
2536 | cb => Coro::unblock_sub { |
2514 | write_runtime |
2537 | write_runtime |
2515 | or warn "ERROR: unable to write runtime file: $!"; |
2538 | or warn "ERROR: unable to write runtime file: $!"; |
2516 | }, |
2539 | }, |
2517 | ); |
2540 | ); |
2518 | |
2541 | |