Created
September 26, 2019 22:21
-
-
Save Vany/7b375071123cacfd3efb81f0a4090cab to your computer and use it in GitHub Desktop.
internal forking webserver template for nvidia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# sudo apt install libanyevent-httpd-perl libanyevent-forkobject-perl | |
use 5.014; | |
use lib qw(.); | |
use AnyEvent::HTTPD; | |
use AnyEvent::ForkObject; | |
use Getopt::Long; | |
use AnyEvent::Log; | |
$AnyEvent::Log::FILTER->level ("info"); | |
use ponch; | |
our $port = 80; | |
GetOptions ("port=i" => \$port) or die("Error in command line arguments\n"); | |
my $httpd = AnyEvent::HTTPD->new(port => $port); | |
my $fo = new AnyEvent::ForkObject; | |
$httpd->reg_cb ( | |
'/' => sub { | |
my ($httpd, $req) = @_; | |
$fo->do(module=>"ponch", method=>"DoSomething", args => [1,2,34,5], cb => sub { | |
my ($stat, $res) = @_; | |
$req->respond ([200, 'OK', {'content-type' => 'text/html'}, | |
"<html><body><h1>Hello World!</h1>" | |
. $res | |
. "</body></html>" | |
]); | |
AE::log(warn => "serving 200 $req->{method} $req->{url}"); | |
}); | |
}); | |
$httpd->run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ponch; | |
use 5.014; | |
use JSON::XS; | |
sub DoSomething { | |
return encode_json({hello => "world", args => \@_}); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment