--- deliantra/server/ext/schmorplog.ext 2007/11/14 08:09:46 1.11
+++ deliantra/server/ext/schmorplog.ext 2008/01/07 01:55:19 1.12
@@ -1,19 +1,30 @@
#! perl # depends=irc
-our $UPDATE_LOGINS = EV::idle Coro::unblock_sub {
+use Fcntl;
+use Coro::AIO;
+
+our $UPDATE_LOGINS = EV::idle sub {
$_[0]->stop;
- my ($status, @pl) = ext::commands::who_listing;
+ cf::async {
+ my ($status, @pl) = ext::commands::who_listing;
+
+ my $fh = aio_open "$LOCALDIR/usercount", O_WRONLY | O_CREAT | O_TRUNC, 0644
+ or return;
+ aio_write $fh, 0, undef, scalar @pl, 0;
+ aio_close $fh;
+
+ my $who;
+ for ($status, @pl) {
+ s/[<&]//g;
+ $who .= "$_
\n";
+ }
- #TODO: write files asynchronously
- open my $fh, ">", "$LOCALDIR/usercount";
- print $fh scalar @pl;
-
- open my $fh, ">", "$LOCALDIR/userlisting.html";
- for ($status, @pl) {
- s/[<&]//g;
- print $fh "$_
\n";
- }
+ my $fh = aio_open "$LOCALDIR/userlisting.html", O_WRONLY | O_CREAT | O_TRUNC, 0644
+ or return;
+ aio_write $fh, 0, undef, $who, 0;
+ aio_close $fh;
+ };
};
cf::player->attach (