# client. From then on, direct TCP connections can be made to this port
# to send requests and get replies.
-do './web-lib.pl';
+BEGIN { push(@INC, ".."); };
+use WebminCore;
use POSIX;
use Socket;
$force_lang = $default_lang;
# Accept the TCP connection
$acptaddr = accept(SOCK, MAIN);
die "accept failed!" if (!$acptaddr);
-select(SOCK); $| = 1;
+$oldsel = select(SOCK);
+$| = 1;
+select($oldsel);
+$rcount = 0;
while(1) {
- # Wait for the request
+ # Wait for the request. Wait longer if this isn't the first one
local $rmask;
vec($rmask, fileno(SOCK), 1) = 1;
- local $sel = select($rmask, undef, undef, 60);
+ local $sel = select($rmask, undef, undef, $rcount ? 360 : 60);
if ($sel <= 0) {
print STDERR "fastrpc: session timed out\n"
if ($gconfig{'rpcdebug'});
print STDERR "fastrpc: check $arg->{'module'}\n" if ($gconfig{'rpcdebug'});
$rawrv = &serialise_variable(
{ 'status' => 1,
- 'rv' => &foreign_check($arg->{'module'}) } );
+ 'rv' => &foreign_check($arg->{'module'}, undef, undef,
+ $arg->{'api'}) } );
}
elsif ($arg->{'action'} eq 'config') {
# Get the config for some module
# execute a function
print STDERR "fastrpc: call $arg->{'module'}::$arg->{'func'}(",join(",", @{$arg->{'args'}}),")\n" if ($gconfig{'rpcdebug'});
local @rv;
- local $main::error_must_die = 1;
eval {
+ local $main::error_must_die = 1;
@rv = &foreign_call($arg->{'module'},
$arg->{'func'},
@{$arg->{'args'}});
$rv = eval $arg->{'code'};
}
print STDERR "fastrpc: eval $arg->{'module'} $arg->{'code'} done = $rv error = $@\n" if ($gconfig{'rpcdebug'});
- $rawrv = &serialise_variable(
- { 'status' => 1, 'rv' => $rv } );
+ if ($@) {
+ $rawrv = &serialise_variable(
+ { 'status' => 0, 'rv' => $@ } );
+ }
+ else {
+ $rawrv = &serialise_variable(
+ { 'status' => 1, 'rv' => $rv } );
+ }
}
elsif ($arg->{'action'} eq 'quit') {
print STDERR "fastrpc: quit\n" if ($gconfig{'rpcdebug'});
print SOCK length($rawrv),"\n";
print SOCK $rawrv;
last if ($arg->{'action'} eq 'quit');
+ $rcount++;
}
# allocate_socket(handle, &port)