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.547 by root, Sun May 9 22:51:13 2010 UTC vs.
Revision 1.548 by root, Mon May 10 21:40:22 2010 UTC

357our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max 357our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max
358 358
359sub encode_json($) { $json_coder->encode ($_[0]) } 359sub encode_json($) { $json_coder->encode ($_[0]) }
360sub decode_json($) { $json_coder->decode ($_[0]) } 360sub decode_json($) { $json_coder->decode ($_[0]) }
361 361
362=item $ref = cf::yaml_load $scalar
363
364Same as YAML::XS::Load, but doesn't leak, because it forks (and thus blocks).
365
366=cut
367
368sub fork_call(&@);
369
370sub yaml_load($) {
371 fork_call { YAML::XS::Load $_[0] } @_
372}
373
362=item cf::post_init { BLOCK } 374=item cf::post_init { BLOCK }
363 375
364Execute the given codeblock, I<after> all extensions have been (re-)loaded, 376Execute the given codeblock, I<after> all extensions have been (re-)loaded,
365but I<before> the server starts ticking again. 377but I<before> the server starts ticking again.
366 378
367The cdoeblock will have a single boolean argument to indicate whether this 379The codeblock will have a single boolean argument to indicate whether this
368is a reload or not. 380is a reload or not.
369 381
370=cut 382=cut
371 383
372sub post_init(&) { 384sub post_init(&) {
583 $EXT_CORO{$coro+0} = $coro; 595 $EXT_CORO{$coro+0} = $coro;
584 596
585 $coro 597 $coro
586} 598}
587 599
588=item fork_call { }, $args 600=item fork_call { }, @args
589 601
590Executes the given code block with the given arguments in a seperate 602Executes the given code block with the given arguments in a seperate
591process, returning the results. Everything must be serialisable with 603process, returning the results. Everything must be serialisable with
592Coro::Storable. May, of course, block. Note that the executed sub may 604Coro::Storable. May, of course, block. Note that the executed sub may
593never block itself or use any form of event handling. 605never block itself or use any form of event handling.
606 # TODO: investigate and fix (likely this will be rather laborious) 618 # TODO: investigate and fix (likely this will be rather laborious)
607 619
608 my @res = Coro::Util::fork_eval { 620 my @res = Coro::Util::fork_eval {
609 cf::post_fork; 621 cf::post_fork;
610 &$cb 622 &$cb
611 }, @args; 623 } @args;
612 624
613 wantarray ? @res : $res[-1] 625 wantarray ? @res : $res[-1]
614} 626}
615 627
616sub objinfo { 628sub objinfo {
3554 3566
3555 0 < aio_load "$CONFDIR/config", my $config 3567 0 < aio_load "$CONFDIR/config", my $config
3556 or die "$CONFDIR/config: $!"; 3568 or die "$CONFDIR/config: $!";
3557 3569
3558 utf8::decode $config; 3570 utf8::decode $config;
3559 3571 *CFG = yaml_load $config;
3560 cf::get_slot 0.1, 10, "reload_config"; # yaml might be slow...
3561 *CFG = YAML::XS::Load $config;
3562 3572
3563 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; 3573 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38];
3564 3574
3565 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; 3575 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset};
3566 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; 3576 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines