File: NoFork.pm

package info (click to toggle)
libhttp-proxy-perl 0.301-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 636 kB
  • ctags: 164
  • sloc: perl: 2,403; makefile: 2
file content (81 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package HTTP::Proxy::Engine::NoFork;
use strict;

our @ISA = qw( HTTP::Proxy::Engine );

__PACKAGE__->make_accessors( 'select' );

sub start {
    my $self = shift;
    my $proxy = $self->proxy;

    $self->select( IO::Select->new( $proxy->daemon ) );

    # clients will not block the proxy by keeping the connection open
    $proxy->max_keep_alive_requests( 1 );
}

sub run {
    my $self  = shift;
    my $proxy = $self->proxy;

    # check for new connections
    for my $fh ( $self->select->can_read() ) {    # there's only one, anyway

        # single-process proxy
        $proxy->serve_connections( $fh->accept );
        $proxy->new_connection;
    }
}

1;

__END__

=head1 NAME

HTTP::Proxy::Engine::NoFork - A basic, non forking HTTP::Proxy engine

=head1 SYNOPSIS

    use HTTP::Proxy;
    my $proxy = HTTP::Proxy->new( engine => 'NoFork' );

=head1 DESCRIPTION

The L<HTTP::Proxy::Engine::NoFork> engine runs the proxy without forking.

=head1 METHODS

=over 4

=item start()

Initialise the engine.

=item run()

Implements the non-forking logic by calling C<< $proxy->serve_requests() >>
directly.

=back

=head1 SEE ALSO

L<HTTP::Proxy>, L<HTTP::Proxy::Engine>.

=head1 AUTHOR

Philippe "BooK" Bruhat, C<< <book@cpan.org> >>.

=head1 COPYRIGHT

Copyright 2005-2013, Philippe Bruhat.

=head1 LICENSE

This module is free software; you can redistribute it or modify it under
the same terms as Perl itself.

=cut