App-MHFS
view release on metacpan or search on metacpan
lib/App/MHFS.pm view on Meta::CPAN
390391392393394395396397398399400401402403404405406407408409410MHFS::Util->
import
();
sub
new {
my
(
$class
,
$launchsettings
,
$plugins
,
$routes
) =
@_
;
$SIG
{PIPE} =
sub
{
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
158815891590159115921593159415951596159715981599160016011602160316041605160616071608# 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
169316941695169616971698169917001701170217031704170517061707170817091710171117121713}
# 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
277527762777277827792780278127822783278427852786278727882789279027912792279327942795my
(
$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
7897789878997900790179027903790479057906790779087909791079117912791379147915791679177918--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
this message
-v|--version
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 )