AnyEvent-FCGI

 view release on metacpan or  search on metacpan

lib/AnyEvent/FCGI.pm  view on Meta::CPAN


This module implements non-blocking FastCGI server for event based applications.

=cut

use strict;
use warnings;

our $VERSION = '0.04';

use Scalar::Util qw/weaken refaddr/;

use AnyEvent;
use AnyEvent::Socket;
use AnyEvent::Handle;
use AnyEvent::FCGI::Connection;

use constant FCGI_VERSION_1 => 1;

use constant FCGI_BEGIN_REQUEST => 1;
use constant FCGI_ABORT_REQUEST => 2;

lib/AnyEvent/FCGI.pm  view on Meta::CPAN


sub new {
    my ($class, %params) = @_;

    my $self = bless {
        connections => {},
        on_request_cb => $params{on_request},
    }, $class;

    my $fcgi = $self;
    weaken($fcgi);

    $params{socket} ||= $params{unix};

    $self->{server} = tcp_server(
        $params{socket} ? 'unix/' : $params{host},
        $params{socket} || $params{port},
        sub {$fcgi->_on_accept(shift)},
        $params{backlog} ? sub {$params{backlog}} : undef
    );

lib/AnyEvent/FCGI/Connection.pm  view on Meta::CPAN

=head1 DESCRIPTION

This module represents a single connection for L<AnyEvent::FCGI>
This module would not be used directly by a program using C<AnyEvent::FCGI>.

=cut

use strict;
use warnings;

use Scalar::Util qw/weaken refaddr/;

use AnyEvent::Handle;
use AnyEvent::FCGI::Request;

use constant MAX_DATA_SIZE => 65535;

sub new {
    my ($class, %params) = @_;
    
    my $self = bless {
        fcgi => $params{fcgi},
        requests => {},
    }, $class;
    
    $self->{io} = new AnyEvent::Handle(
        fh => $params{fh},
        on_error => sub {$self->_on_error(@_)},
    );
    $self->{io}->push_read(chunk => 8, sub {$self->_on_read_header(@_)});
    
    weaken($self->{fcgi});
    
    return $self;
}

sub _on_error {
    my ($self, $io, $fatal, $message) = @_;
    
    if ($fatal) {
        $self->_shutdown;
    }

lib/AnyEvent/FCGI/Request.pm  view on Meta::CPAN


This module would not be used directly by a program using C<AnyEvent::FCGI>, but
rather, objects in this class are passed into the C<on_request> callback of
the containing C<AnyEvent::FCGI> object.

=cut

use strict;
use warnings;

use Scalar::Util qw/weaken/;

sub new {
    my ($class, %params) = @_;
    
    my $self = bless {
        id => $params{id},
        fcgi => $params{fcgi},
        connection => $params{connection},
        flags => $params{flags},
        
        stdin => '',
        stdin_done => 0,
        params => {},
        params_string => '',
        params_done => 0,
        
        used_stderr => 0,
    }, $class;
    
    weaken($self->{fcgi});
    weaken($self->{connection});

    return $self;
}

sub _ready_check {
    my $self = shift;
    
    if ($self->{stdin_done} && $self->{params_done} && $self->{fcgi}) {
        $self->{fcgi}->_request_ready($self);
    }



( run in 0.454 second using v1.01-cache-2.11-cpan-65fba6d93b7 )