This commit is contained in:
2019-02-06 00:49:12 +03:00
commit 8dbb1bb605
4796 changed files with 506072 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
Makefile.PL
MANIFEST
mogstored
mogilefsd
META.yml Module meta-data (added by MakeMaker)

View File

@@ -0,0 +1,13 @@
^#
\bCVS\b
^MANIFEST\.
^Makefile$
~$
\.html$
\.old$
^blib/
_blib$
^MakeMaker-\d
^\.exists
\bdebian\b
\bconf\b

View File

@@ -0,0 +1,17 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: mogilefs-server
version: 1.00
version_from:
installdirs: site
requires:
Danga::Socket: 1.22
fields: 0
Getopt::Long: 0
Linux::AIO: 1.3
Perlbal: 0
Symbol: 0
Sys::Syslog: 0
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17

View File

@@ -0,0 +1,42 @@
#!/usr/bin/perl
#
# Perl Makefile for Danga-Socket
# $Id: Makefile.PL,v 1.1 2005/02/01 01:17:53 bradfitz Exp $
#
# Invoke with 'perl Makefile.PL'
#
# See ExtUtils::MakeMaker (3) for more information on how to influence
# the contents of the Makefile that is written
#
use ExtUtils::MakeMaker;
my $exefiles = ["mogstored", "mogilefsd"];
$exefiles = ["mogstored"] if exists $ENV{DANGABUILD_MOGSTOREDONLY};
$exefiles = ["mogilefsd"] if exists $ENV{DANGABUILD_MOGILEFSDONLY};
WriteMakefile(
NAME => 'mogilefs-server',
VERSION => '1.00',
AUTHOR => 'Brad Fitzpatrick <brad@danga.com>',
ABSTRACT => 'MogileFS server components',
EXE_FILES => $exefiles,
PREREQ_PM => {
'Danga::Socket' => '1.22',
'Perlbal' => 0, # FIXME: add version to Perlbal
'Linux::AIO' => '1.3',
'Sys::Syslog' => 0,
'Getopt::Long' => 0,
'Symbol' => 0,
fields => 0,
},
dist => {
CI => "cvs commit",
RCS_LABEL => 'cvs tag RELEASE_$(VERSION_SYM)',
SUFFIX => ".gz",
DIST_DEFAULT => 'all tardist',
COMPRESS => "gzip",
},
);

View File

@@ -0,0 +1,10 @@
#daemonize = 1
db_dsn = DBI:mysql:mogilefs:host=127.0.0.1
db_user = username
db_pass = password
conf_port = 7001
listener_jobs = 10
delete_jobs = 1
replicate_jobs = 5
mog_root = /mnt/mogilefs
reaper_jobs = 1

View File

@@ -0,0 +1,11 @@
SERVER max_connections = 10000
CREATE SERVICE mogstored
SET mogstored.role = web_server
SET mogstored.listen = 0.0.0.0:7500
SET mogstored.docroot = #MOGSTORED_DOCROOT
SET mogstored.dirindexing = 0
SET mogstored.enable_put = 1
SET mogstored.enable_delete = 1
SET mogstored.min_put_directory = 1
ENABLE mogstored

View File

@@ -0,0 +1,5 @@
mogilefs-server (1.00-1) unstable; urgency=low
* Initial release
-- Jay Bonci <jaybonci@debian.org> Fri, 14 Jan 2005 15:41:28 -0500

View File

@@ -0,0 +1 @@
4

View File

@@ -0,0 +1,25 @@
Source: mogilefs-server
Section: perl
Priority: optional
Maintainer: Jay Bonci <jaybonci@debian.org>
Build-Depends-Indep: debhelper (>= 4.1.40), perl (>= 5.6.0-16), libdbd-mysql-perl, libdbi-perl, libperlbal-perl, liblinux-aio-perl, po-debconf, libnet-netmask-perl, libwww-perl
Standards-Version: 3.6.1.0
Package: mogilefsd
Architecture: all
Depends: ${perl:Depends}, libdbd-mysql-perl, libdbi-perl, debconf (>= 1.2.0), libnet-netmask-perl, libwww-perl
Suggests: libmogilefs-perl, mogilefs-utils
Description: scalable distributed filesystem from Danga Interactive
MogileFS is an open-source, application-level distributed filesystem. It
creates a host-nuetral, filesystem-agnostic method of distributing files
that has many advantages over NFS and single-machine raid. This set
of utilities is very scalable and can handle Livejournal.com's load, for
which it was designed.
Package: mogstored
Architecture: all
Depends: ${perl:Depends}, libperlbal-perl, liblinux-aio-perl, debconf (>= 1.2.0)
Suggests: mogilefs-utils
Description: storage node daemon for MogileFS
Mogstored is a storage node daemon for MogileFS, the open-source
application-level distributed filesystem from Danga Interactive.

View File

@@ -0,0 +1,27 @@
This package was debianized by Jay Bonci <jay@bonci.com> on
Fri Jan 14 15:57:37 EST 2005
It was downloaded from: http://www.danga.com/dist/MogileFS/server/
Upstream Author:
Brad Fitzpatrick <brad@danga.com>
Brad Whitaker <whitaker@danga.com>
Mark Smith <junior@danga.com>
Copyright:
This program is free software; you can redistribute it and/or modify
it under the terms of either:
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
See:
/usr/share/common-licenses/Artistic
/usr/share/common-licenses/GPL
For more information regarding these licensing options

View File

@@ -0,0 +1,26 @@
#!/bin/sh
PACKAGE=mogilefsd
set -e
. /usr/share/debconf/confmodule
RUNASUSER=""
while [ "$RUNASUSER" = "" ]
do
db_input medium $PACKAGE/runasuser || true
db_go
db_get $PACKAGE/runasuser
RUNASUSER="$RET"
if [ "$RUNASUSER" = "root" ]
then
db_reset $PACKAGE/runasuser
db_fset $PACKAGE/runasuser seen false
fi
done

View File

@@ -0,0 +1,91 @@
#! /bin/sh
#
# skeleton example file to build /etc/init.d/ scripts.
# This file should be used to construct scripts for /etc/init.d.
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian
# by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/mogilefsd
NAME=mogilefsd
DESC=mogilefsd
DEFAULTS=/etc/default/$NAME
PIDFILE=/var/run/$NAME.pid
test -x $DAEMON || exit 0
if [ ! -e $DEFAULTS ]
then
echo "Can't start $NAME. Defaults file ($DEFAULTS) doesn't exist."
echo "Please run dpkg-reconfigure $NAME to correct the problem."
exit 0
fi
#Read defaults file
[ -r $DEFAULTS ] && . $DEFAULTS
if [ "$MOGILEFSD_RUNASUSER" == "" ]
then
echo "Cannot determine user to run as, even though defaults file ($DEFAULTS) exists."
echo "Please run dpkg-reconfigure $NAME to correct the problem."
exit 0
fi
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
if [ -e $PIDFILE ]
then
if [ -d /proc/`cat $PIDFILE`/ ]
then
echo "$NAME already running."
exit 0;
else
rm -f $PIDFILE
fi
fi
start-stop-daemon --start --quiet --exec $DAEMON --pidfile $PIDFILE -b -m --name $NAME --chuid $MOGILEFSD_RUNASUSER
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --name $NAME --user $MOGILEFSD_RUNASUSER
echo "$NAME."
rm -f $PIDFILE
;;
restart|force-reload)
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart".
#
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --name $NAME --user $MOGILEFSD_RUNASUSER
rm -f $PIDFILE
sleep 1
start-stop-daemon --start --quiet --exec $DAEMON --pidfile $PIDFILE -b -m --name $NAME --chuid $MOGILEFSD_RUNASUSER
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0

View File

@@ -0,0 +1,33 @@
#!/bin/sh
PKG=mogilefsd
DEFAULTFILE=/etc/default/$PKG
. /usr/share/debconf/confmodule || exit 0
#DEBHELPER#
set -e
case "$1" in
configure)
if [ ! -e /etc/mogilefs/mogilefsd.conf ]
then
mkdir -p /etc/mogilefs
cp /usr/share/mogilefsd/mogilefsd.conf.default /etc/mogilefs/mogilefsd.conf
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
db_stop

View File

@@ -0,0 +1,15 @@
#!/bin/sh
#DEBHELPER#
if [ "$1" = "purge" ]
then
rm -f /etc/mogilefs/mogilefsd.conf
rm -f /etc/default/mogilefsd
[ -d /etc/mogilefs ] && rmdir --ignore-fail-on-non-empty /etc/mogilefs
rmdir --ignore-fail-on-non-empty /etc/default
fi
rm -f /var/run/mogilefsd.pid

View File

@@ -0,0 +1,24 @@
#!/bin/sh
PKG=mogilefsd
DEFAULTFILE=/etc/default/$PKG
. /usr/share/debconf/confmodule || exit 0
#DEBHELPER#
set -e
db_get $PKG/runasuser
RUNAS=$RET
getent passwd $RUNAS >/dev/null || adduser --system $RUNAS
if [ ! -e $DEFAULTFILE ]
then
mkdir -p /etc/default
echo "#!/bin/sh" >> $DEFAULTFILE
echo "# Defaults for the mogilefsd package" >> $DEFAULTFILE
echo "MOGILEFSD_RUNASUSER=$RUNAS" >> $DEFAULTFILE
fi

View File

@@ -0,0 +1,7 @@
Template: mogilefsd/runasuser
Type: string
_Default: mogilefsd
_Description: User to run mogilefsd as:
The mogilefsd storage engine cannot be run as root. What user should it be
run as? This user will be created for you as a system user if it does not
yet exist.

View File

@@ -0,0 +1,9 @@
#!/bin/sh
PACKAGE=mogstored
set -e
. /usr/share/debconf/confmodule
db_input medium $PACKAGE/docroot || true
db_go

View File

@@ -0,0 +1,72 @@
#! /bin/sh
#
# skeleton example file to build /etc/init.d/ scripts.
# This file should be used to construct scripts for /etc/init.d.
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian
# by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/mogstored
NAME=mogstored
DESC=mogstored
PIDFILE=/var/run/$NAME.pid
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
if [ -e $PIDFILE ]
then
if [ -d /proc/`cat $PIDFILE`/ ]
then
echo "$NAME already running."
exit 0;
else
rm -f $PIDFILE
fi
fi
start-stop-daemon --start --quiet --exec $DAEMON --pidfile $PIDFILE -b -m --name $NAME
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --name $NAME
echo "$NAME."
rm -f $PIDFILE
;;
restart|force-reload)
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart".
#
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --name $NAME
rm -f $PIDFILE
sleep 1
start-stop-daemon --start --quiet --exec $DAEMON --pidfile $PIDFILE -b -m --name $NAME
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0

View File

@@ -0,0 +1,47 @@
#!/bin/sh
PKG=mogstored
. /usr/share/debconf/confmodule || exit 0
set -e
case "$1" in
configure)
if [ ! -e /etc/mogilefs/mogstored.conf ]
then
mkdir -p /etc/mogilefs
cp /usr/share/mogstored/mogstored.conf.default /etc/mogilefs/mogstored.conf
db_get $PKG/docroot
MOGSTORED_DOCROOT=$RET
if [ ! -d "$MOGSTORED_DOCROOT" ]
then
mkdir -p $MOGSTORED_DOCROOT
chmod 755 $MOGSTORED_DOCROOT
fi
perl -pi -e "s|#MOGSTORED_DOCROOT|$MOGSTORED_DOCROOT|" /etc/mogilefs/mogstored.conf
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
db_stop
#DEBHELPER#

View File

@@ -0,0 +1,24 @@
#!/bin/sh
PKG=mogstored
. /usr/share/debconf/confmodule || exit 0
if [ "$1" = "purge" ]
then
rm -f /etc/mogilefs/mogstored.conf
rmdir --ignore-fail-on-non-empty /etc/mogilefs
db_get $PKG/docroot
DOCROOT=$RET
rmdir --ignore-fail-on-non-empty $DOCROOT &> /dev/null
fi
#DEBHELPER#
rm -f /var/run/mogstored.pid

View File

@@ -0,0 +1,5 @@
Template: mogstored/docroot
Type: string
_Default: /var/mogdata
_Description: Document root for mogstored:
The mogstored daemon needs a directory for the root of its filetree.

View File

@@ -0,0 +1,2 @@
[type: gettext/rfc822deb] mogstored.templates
[type: gettext/rfc822deb] mogilefsd.templates

View File

@@ -0,0 +1,64 @@
#
# Translators, if you are not familiar with the PO format, gettext
# documentation is worth reading, especially sections dedicated to
# this format, e.g. by running:
# info -n '(gettext)PO Files'
# info -n '(gettext)Header Entry'
#
# Some information specific to po-debconf are available at
# /usr/share/doc/po-debconf/README-trans
# or http://www.debian.org/intl/l10n/po-debconf/README-trans
#
# Developers do not need to manually edit POT or PO files.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2005-01-19 13:36-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#. Type: string
#. Default
#: ../mogstored.templates:3
msgid "/var/mogdata"
msgstr ""
#. Type: string
#. Description
#: ../mogstored.templates:4
msgid "Document root for mogstored:"
msgstr ""
#. Type: string
#. Description
#: ../mogstored.templates:4
msgid "The mogstored daemon needs a directory for the root of its filetree."
msgstr ""
#. Type: string
#. Default
#: ../mogilefsd.templates:3
msgid "mogilefsd"
msgstr ""
#. Type: string
#. Description
#: ../mogilefsd.templates:4
msgid "User to run mogilefsd as:"
msgstr ""
#. Type: string
#. Description
#: ../mogilefsd.templates:4
msgid ""
"The mogilefsd storage engine cannot be run as root. What user should it be "
"run as? This user will be created for you as a system user if it does not "
"yet exist."
msgstr ""

View File

@@ -0,0 +1,80 @@
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# This is the debhelper compatibility version to use.
# export DH_COMPAT=4
ENV=/usr/bin/env
PERL=/usr/bin/perl
MOGILEFSD_PACKAGE=mogilefsd
MOGSTORED_PACKAGE=mogstored
MOGILEFSD_CONFDIR=$(CURDIR)/debian/$(MOGILEFSD_PACKAGE)/usr/share/$(MOGILEFSD_PACKAGE)
MOGSTORED_CONFDIR=$(CURDIR)/debian/$(MOGSTORED_PACKAGE)/usr/share/$(MOGSTORED_PACKAGE)
MOGILEFSDBLIB=blib.mogilefsd
MOGSTOREDBLIB=blib.mogstored
build:
dh_testdir
# Add here commands to compile the package.
$(ENV) DANGABUILD_MOGILEFSDONLY=1 perl Makefile.PL verbose INSTALLDIRS=vendor INST_SCRIPT=$(MOGILEFSDBLIB)
cp Makefile Makefile.mogilefsd
$(ENV) DANGABUILD_MOGSTOREDONLY=1 perl Makefile.PL verbose INSTALLDIRS=vendor INST_SCRIPT=$(MOGSTOREDBLIB)
cp Makefile Makefile.mogstored
clean:
dh_testdir
dh_testroot
-$(MAKE) clean
rm -f Makefile.old Makefile.mogilefsd Makefile.mogstored
rm -rf $(MOGILEFSDBLIB) $(MOGSTOREDBLIB)
dh_clean
install:
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
$(MAKE) -f Makefile.mogilefsd PREFIX=$(CURDIR)/debian/$(MOGILEFSD_PACKAGE)/usr OPTIMIZE="-O2 -g -Wall" test install
$(MAKE) -f Makefile.mogstored PREFIX=$(CURDIR)/debian/$(MOGSTORED_PACKAGE)/usr OPTIMIZE="-O2 -g -Wall" test install
#There is no test suite, so smoke-test here
perl -c $(CURDIR)/mogilefsd
perl -c $(CURDIR)/mogstored
install -d $(MOGILEFSD_CONFDIR)
install -m 644 $(CURDIR)/conf/mogilefsd.conf $(MOGILEFSD_CONFDIR)/mogilefsd.conf.default
install -d $(MOGSTORED_CONFDIR)
install -m 644 $(CURDIR)/conf/mogstored.conf $(MOGSTORED_CONFDIR)/mogstored.conf.default
-find $(CURDIR)/debian -type d | xargs rmdir -p --ignore-fail-on-non-empty
binary-arch:;
binary-indep: build install
dh_testdir
dh_testroot
dh_installdocs
dh_installman
dh_installdebconf
dh_installinit
dh_installchangelogs
dh_link
dh_strip
dh_compress
dh_fixperms
dh_installdeb
dh_perl
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure

View File

@@ -0,0 +1,2 @@
version=2
http://www.danga.com/dist/MogileFS/server/mogilefs-server-([0-9].*)\.tar.gz

3037
wcmtools/mogilefs/server/mogilefsd Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,198 @@
#!/usr/bin/perl -w
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
if 0; # not running under some shell
#
# MogileFS storage node daemon
# (perlbal front-end)
#
# (c) 2004, Brad Fitzpatrick, <brad@danga.com>
use strict;
use lib 'lib';
use Perlbal;
use Linux::AIO '1.3';
use IO::Socket::INET;
my $opt_daemonize;
my $opt_config;
exit 1 unless
Getopt::Long::GetOptions(
'daemon' => \$opt_daemonize,
'config=s' => \$opt_config,
);
my $default_config = "/etc/mogilefs/mogstored.conf";
$opt_config = $default_config if ! $opt_config && -e $default_config;
my $conf;
if (-e $opt_config) {
if (open F, $opt_config) {
local $/ = undef;
$conf = <F>;
close F;
} else {
die "Couldn't open config file ($opt_config): $!\n";
}
}
my $out = sub { print STDOUT join("\n", map { ref $_ eq 'ARRAY' ? @$_ : $_ } @_) . "\n"; };
my $path = "/var/mogdata";
my $listen = "0.0.0.0:7500";
$conf ||= "
SERVER max_connections = 10000
CREATE SERVICE mogstored
SET mogstored.role = web_server
SET mogstored.listen = $listen
SET mogstored.docroot = $path
SET mogstored.dirindexing = 0
SET mogstored.enable_put = 1
SET mogstored.enable_delete = 1
SET mogstored.min_put_directory = 1
SET mogstored.persist_client = 1
ENABLE mogstored
";
Perlbal::run_manage_command($_, $out) foreach split(/\n/, $conf);
unless (Perlbal::Socket->WatchedSockets() > 0) {
die "Invalid configuration. (shouldn't happen?) Stopping.\n";
}
if ($opt_daemonize) {
Perlbal::daemonize();
} else {
print "Running.\n";
}
# register our disk usage callback to get disk usage and keep an eye on how we're doing
Perlbal::Socket::register_callback(1, sub {
my $err = sub { Perlbal::log('crit', $_[0]); return 60; };
my $rval = `df -l`;
foreach my $l (split /\r?\n/, $rval) {
next unless $l =~ /^(.+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(.+)\s+(.+)$/;
my ($dev, $total, $used, $avail, $use, $disk) = ($1, $2, $3, $4, $5, $6);
next unless $disk =~ /^$path/;
# create string to print
my $now = time;
my $output = "time: $now\ndevice: $dev\ntotal: $total\nused: $used\navailable: $avail\nuse: $use\ndisk: $disk\n";
# open a file on that disk location called 'usage'
my $rv = open(FILE, ">$disk/usage");
unless ($rv) {
$err->("Unable to open '$disk/usage' for writing: $!");
next;
}
print FILE $output;
close FILE;
}
return 60;
});
# setup a new socket for handling size requests
my $server = IO::Socket::INET->new(LocalPort => 7501, # FIXME make this configurable
Type => SOCK_STREAM,
Proto => 'tcp',
Blocking => 0,
Reuse => 1,
Listen => 10 )
or die "Error creating socket: $@\n";
# in Perl 5.6, we weren't always seeing this turned off by IO::Socket
# so we have to do it manually here just to be sure.
IO::Handle::blocking($server, 0);
# accept handler for new workers
my $accept_handler = sub {
my $csock = $server->accept()
or return;
IO::Handle::blocking($csock, 0);
my $client = SideChannelClient->new($csock);
$client->watch_read(1);
# ... that's it. Client->new adds to event loop.
};
# add to fd list so this one gets processed
Perlbal::Socket->AddOtherFds(fileno($server) => $accept_handler);
# now start the main loop
Perlbal::run();
#############################################################################
### simple package for handling the stream request port
package SideChannelClient;
use base qw{Perlbal::Socket};
use fields qw{count};
# needed since we're pretending to be a Perlbal::Socket... never idle out
sub max_idle_time { return 0; }
sub new {
my SideChannelClient $self = shift;
$self = fields::new($self) unless ref $self;
$self->SUPER::new(@_);
$self->state('side_channel');
$self->{count} = 0;
return $self;
}
sub event_read {
my SideChannelClient $self = shift;
my $bref = $self->read(1024);
return $self->close() unless defined $bref;
$self->{read_buf} .= $$bref;
while ($self->{read_buf} =~ s/^(.+?)\r?\n//) {
my $cmd = $1;
if ($cmd =~ /^size (\S+)$/) {
# increase our count
$self->{count}++;
# validate uri
my $uri = $1;
if ($uri =~ /\.\./) {
$self->write("ERROR: uri invalid (contains ..)\r\n");
return;
}
# now stat the file to get the size and such
Linux::AIO::aio_stat("$path$uri", sub {
return if $self->{closed};
my $size = -e _ ? -s _ : -1;
$self->write("$uri $size\r\n");
});
} else {
# we don't understand this so pass it on to manage command interface
my @out;
Perlbal::run_manage_command($cmd, sub { push @out, $_[0]; });
$self->write(join("\r\n", @out) . "\r\n");
}
}
}
# override Danga::Socket's event handlers which die
sub event_err { $_[0]->close; }
sub event_hup { $_[0]->close; }
# as_string handler
sub as_string {
my SideChannelClient $self = shift;
my $ret = $self->SUPER::as_string;
$ret .= "; size_requests=$self->{count}";
return $ret;
}
# Local Variables:
# mode: perl
# c-basic-indent: 4
# indent-tabs-mode: nil
# End: