App-MHFS

 view release on metacpan or  search on metacpan

lib/App/MHFS.pm  view on Meta::CPAN

--cfgdir              location of configuration directory, will be created if
  it does not exist
--appdir              location of application static files
--fallback_data_root  location to fallback to if setting isn't found instead of
  $HOME or $APPDIR\mhfs
-h|--help             print this message
-v|--version          print version
END_USAGE

sub run {
    binmode(STDOUT, ":utf8");
    binmode(STDERR, ":utf8");

    # parse command line args into launchsettings
    my %launchsettings;
    my ($flush, $cfgdir, $fallback_data_root, $appdir, $help, $versionflag, $debug);
    if(!GetOptions(
        'flush' => \$flush,
        'cfgdir=s' => \$cfgdir,
        'fallback_data_root=s' => \$fallback_data_root,
        'appdir=s' => \$appdir,
        'help|h' =>\$help,

lib/MHFS/HTTP/Server.pm  view on Meta::CPAN

use MHFS::Util qw(parse_ipv4 read_text_file);

sub new {
    my ($class, $launchsettings, $plugins, $routes) = @_;

    local $SIG{PIPE} = sub {
        print STDERR "SIGPIPE @_\n";
    };
    local $SIG{ __DIE__ } = \&Carp::confess if ($launchsettings->{debug});

    binmode(STDOUT, ":utf8");
    binmode(STDERR, ":utf8");

    # load settings
    say __PACKAGE__.": loading settings";
    my $settings = MHFS::Settings::load($launchsettings);
    if((exists $settings->{'flush'}) && ($settings->{'flush'})) {
        say __PACKAGE__.": setting autoflush on STDOUT and STDERR";
        STDOUT->autoflush(1);
        STDERR->autoflush(1);
    }

lib/MHFS/HTTP/Server/Client/Request.pm  view on Meta::CPAN

    # open the file and get the size
    my %fileitem = ('requestfile' => $requestfile);
    my $currentsize;
    if($self->{'method'} ne 'HEAD') {
        my $FH;
        if(! open($FH, "<", $requestfile)) {
            say "SLF: open failed";
            $self->Send404;
            return;
        }
        binmode($FH);
        my $st = stat($FH);
        if(! $st) {
            $self->Send404();
            return;
        }
        $currentsize = $st->size;
        $fileitem{'fh'} = $FH;
    }
    else {
        $currentsize = (-s $requestfile);

lib/MHFS/HTTP/Server/Client/Request.pm  view on Meta::CPAN

}

# currently only supports fixed filelength
sub SendPipe {
    my ($self, $FH, $filename, $filelength, $mime) = @_;
    if(! defined $filelength) {
        $self->Send404();
    }

    $mime //= getMIME($filename);
    binmode($FH);
    my %fileitem;
    $fileitem{'fh'} = $FH;
    $fileitem{'get_current_length'} = sub {
        my $tocheck = defined $self->{'header'}{'_RangeEnd'} ? $self->{'header'}{'_RangeEnd'}+1 : $filelength;
        return min($filelength, $tocheck);
    };

    $self->_SendDataItem(\%fileitem, {
        'size'     => $filelength,
        'mime'     => $mime,

lib/MHFS/Process.pm  view on Meta::CPAN

    my ($mpa, $prochandlers, $handlesettings) = @_;

    my %self = ('time' => clock_gettime(CLOCK_MONOTONIC), 'evp' => $mpa->{'evp'});
    # inreader/inwriter   is the parent to child data channel
    # outreader/outwriter is the child to parent data channel
    # errreader/errwriter is the child to parent log channel
    pipe(my $inreader, my $inwriter)   or die("pipe failed $!");
    pipe(my $outreader, my $outwriter) or die("pipe failed $!");
    pipe(my $errreader, my $errwriter) or die("pipe failed $!");
    # the childs stderr will be UTF-8 text
    binmode($errreader, ':encoding(UTF-8)');
    my $pid = fork() // do {
        say "failed to fork";
        return undef;
    };
    if($pid == 0) {
        close($inwriter);
        close($outreader);
        close($errreader);
        open(STDIN,  "<&", $inreader) or die("Can't dup \$inreader to STDIN");
        open(STDOUT, ">&", $errwriter) or die("Can't dup \$errwriter to STDOUT");



( run in 2.876 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )