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.174 by root, Sun Jan 14 19:55:37 2007 UTC vs.
Revision 1.177 by root, Sun Jan 14 22:54:18 2007 UTC

8use Storable; 8use Storable;
9use Opcode; 9use Opcode;
10use Safe; 10use Safe;
11use Safe::Hole; 11use Safe::Hole;
12 12
13use Coro 3.3 (); 13use Coro 3.4 ();
14use Coro::Event; 14use Coro::Event;
15use Coro::Timer; 15use Coro::Timer;
16use Coro::Signal; 16use Coro::Signal;
17use Coro::Semaphore; 17use Coro::Semaphore;
18use Coro::AIO; 18use Coro::AIO;
1846 1846
1847 $rmp->{random_seed} ||= $exit->random_seed; 1847 $rmp->{random_seed} ||= $exit->random_seed;
1848 1848
1849 my $data = cf::to_json $rmp; 1849 my $data = cf::to_json $rmp;
1850 my $md5 = Digest::MD5::md5_hex $data; 1850 my $md5 = Digest::MD5::md5_hex $data;
1851 my $meta = "$cf::RANDOM_MAPS/$md5.meta";
1851 1852
1852 if (my $fh = aio_open "$cf::RANDOM_MAPS/$md5.meta", O_WRONLY | O_CREAT, 0666) { 1853 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) {
1853 aio_write $fh, 0, (length $data), $data, 0; 1854 aio_write $fh, 0, (length $data), $data, 0;
1855 undef $fh;
1856 aio_rename "$meta~", $meta;
1854 1857
1855 $exit->slaying ("?random/$md5"); 1858 $exit->slaying ("?random/$md5");
1856 $exit->msg (undef); 1859 $exit->msg (undef);
1857 } 1860 }
1858} 1861}
2228 2231
2229sub main { 2232sub main {
2230 # we must not ever block the main coroutine 2233 # we must not ever block the main coroutine
2231 local $Coro::idle = sub { 2234 local $Coro::idle = sub {
2232 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 2235 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
2236 (async {
2233 async { Event::one_event }; 2237 Event::one_event;
2238 })->prio (Coro::PRIO_MAX);
2234 }; 2239 };
2235 2240
2236 cfg_load; 2241 cfg_load;
2237 db_load; 2242 db_load;
2238 load_extensions; 2243 load_extensions;
2386 } 2391 }
2387 2392
2388 warn "reloaded"; 2393 warn "reloaded";
2389}; 2394};
2390 2395
2396our $RELOAD_WATCHER; # used only during reload
2397
2391register_command "reload" => sub { 2398register_command "reload" => sub {
2392 my ($who, $arg) = @_; 2399 my ($who, $arg) = @_;
2393 2400
2394 if ($who->flag (FLAG_WIZ)) { 2401 if ($who->flag (FLAG_WIZ)) {
2395 $who->message ("start of reload."); 2402 $who->message ("reloading server.");
2403
2404 # doing reload synchronously and two reloads happen back-to-back,
2405 # coro crashes during coro_state_free->destroy here.
2406
2407 $RELOAD_WATCHER ||= Event->timer (after => 0, data => WF_AUTOCANCEL, cb => sub {
2396 reload; 2408 reload;
2397 $who->message ("end of reload."); 2409 undef $RELOAD_WATCHER;
2410 });
2398 } 2411 }
2399}; 2412};
2400 2413
2401unshift @INC, $LIBDIR; 2414unshift @INC, $LIBDIR;
2402 2415

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines