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.86 by root, Thu Dec 14 05:09:32 2006 UTC vs.
Revision 1.88 by root, Fri Dec 15 19:29:18 2006 UTC

16# work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode? 16# work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode?
17$YAML::Syck::ImplicitUnicode = 1; 17$YAML::Syck::ImplicitUnicode = 1;
18 18
19use strict; 19use strict;
20 20
21sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload
22
21our %COMMAND = (); 23our %COMMAND = ();
22our %COMMAND_TIME = (); 24our %COMMAND_TIME = ();
23our %EXTCMD = (); 25our %EXTCMD = ();
24 26
25_init_vars; 27_init_vars;
26 28
27our @EVENT; 29our @EVENT;
28our $LIBDIR = maps_directory "perl"; 30our $LIBDIR = datadir . "/ext";
29 31
30our $TICK = MAX_TIME * 1e-6; 32our $TICK = MAX_TIME * 1e-6;
31our $TICK_WATCHER; 33our $TICK_WATCHER;
32our $NEXT_TICK; 34our $NEXT_TICK;
33 35
718 720
719 Symbol::delete_package $pkg; 721 Symbol::delete_package $pkg;
720} 722}
721 723
722sub load_extensions { 724sub load_extensions {
723 my $LIBDIR = maps_directory "perl";
724
725 for my $ext (<$LIBDIR/*.ext>) { 725 for my $ext (<$LIBDIR/*.ext>) {
726 next unless -r $ext; 726 next unless -r $ext;
727 eval { 727 eval {
728 load_extension $ext; 728 load_extension $ext;
729 1 729 1
1023 sub db_sync() { 1023 sub db_sync() {
1024 db_save if $dirty; 1024 db_save if $dirty;
1025 undef $dirty; 1025 undef $dirty;
1026 } 1026 }
1027 1027
1028 my $idle = Event->idle (min => $TICK * 2.8, max => 10, repeat => 0, cb => sub { 1028 my $idle = Event->idle (min => $TICK * 2.8, max => 10, repeat => 0, data => WF_AUTOCANCEL, cb => sub {
1029 db_sync; 1029 db_sync;
1030 }); 1030 });
1031 1031
1032 sub db_dirty() { 1032 sub db_dirty() {
1033 $dirty = 1; 1033 $dirty = 1;
1083 1083
1084 $msg->("reloading..."); 1084 $msg->("reloading...");
1085 1085
1086 eval { 1086 eval {
1087 # cancel all watchers 1087 # cancel all watchers
1088 $_->cancel for Event::all_watchers; 1088 for (Event::all_watchers) {
1089 $_->cancel if $_->data & WF_AUTOCANCEL;
1090 }
1089 1091
1090 # unload all extensions 1092 # unload all extensions
1091 for (@exts) { 1093 for (@exts) {
1092 $msg->("unloading <$_>"); 1094 $msg->("unloading <$_>");
1093 unload_extension $_; 1095 unload_extension $_;
1172 1174
1173$TICK_WATCHER = Event->timer ( 1175$TICK_WATCHER = Event->timer (
1174 prio => 1, 1176 prio => 1,
1175 async => 1, 1177 async => 1,
1176 at => $NEXT_TICK || 1, 1178 at => $NEXT_TICK || 1,
1179 data => WF_AUTOCANCEL,
1177 cb => sub { 1180 cb => sub {
1178 cf::server_tick; # one server iteration 1181 cf::server_tick; # one server iteration
1179 1182
1180 my $NOW = Event::time; 1183 my $NOW = Event::time;
1181 $NEXT_TICK += $TICK; 1184 $NEXT_TICK += $TICK;
1191IO::AIO::max_poll_time $TICK * 0.2; 1194IO::AIO::max_poll_time $TICK * 0.2;
1192 1195
1193Event->io (fd => IO::AIO::poll_fileno, 1196Event->io (fd => IO::AIO::poll_fileno,
1194 poll => 'r', 1197 poll => 'r',
1195 prio => 5, 1198 prio => 5,
1199 data => WF_AUTOCANCEL,
1196 cb => \&IO::AIO::poll_cb); 1200 cb => \&IO::AIO::poll_cb);
1197 1201
11981 12021
1199 1203

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines