… | |
… | |
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 | |
19 | use strict; |
19 | use strict; |
20 | |
20 | |
|
|
21 | sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload |
|
|
22 | |
21 | our %COMMAND = (); |
23 | our %COMMAND = (); |
22 | our %COMMAND_TIME = (); |
24 | our %COMMAND_TIME = (); |
23 | our %EXTCMD = (); |
25 | our %EXTCMD = (); |
24 | |
26 | |
25 | _init_vars; |
27 | _init_vars; |
26 | |
28 | |
27 | our @EVENT; |
29 | our @EVENT; |
28 | our $LIBDIR = maps_directory "perl"; |
30 | our $LIBDIR = datadir . "/ext"; |
29 | |
31 | |
30 | our $TICK = MAX_TIME * 1e-6; |
32 | our $TICK = MAX_TIME * 1e-6; |
31 | our $TICK_WATCHER; |
33 | our $TICK_WATCHER; |
32 | our $NEXT_TICK; |
34 | our $NEXT_TICK; |
33 | |
35 | |
… | |
… | |
718 | |
720 | |
719 | Symbol::delete_package $pkg; |
721 | Symbol::delete_package $pkg; |
720 | } |
722 | } |
721 | |
723 | |
722 | sub load_extensions { |
724 | sub 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; |
… | |
… | |
1191 | IO::AIO::max_poll_time $TICK * 0.2; |
1194 | IO::AIO::max_poll_time $TICK * 0.2; |
1192 | |
1195 | |
1193 | Event->io (fd => IO::AIO::poll_fileno, |
1196 | Event->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 | |
1198 | 1 |
1202 | 1 |
1199 | |
1203 | |