App-MHFS

 view release on metacpan or  search on metacpan

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

390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
MHFS::Util->import();
 
sub new {
    my ($class, $launchsettings, $plugins, $routes) = @_;
 
    $SIG{PIPE} = sub {
        print STDERR "SIGPIPE @_\n";
    };
 
    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/App/MHFS.pm  view on Meta::CPAN

1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
# 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/App/MHFS.pm  view on Meta::CPAN

1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
}
 
# 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/App/MHFS.pm  view on Meta::CPAN

2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
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");

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

7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
--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);
    if(!GetOptions(
        'flush' => \$flush,
        'cfgdir=s' => \$cfgdir,
        'fallback_data_root=s' => \$fallback_data_root,
        'appdir=s' => \$appdir,
        '--help|h' =>\$help,



( run in 0.241 second using v1.01-cache-2.11-cpan-2b0bae70ee8 )