perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Farber <>
Subject Path to my module and APR::Socket::send() usage
Date Thu, 21 Oct 2010 12:35:00 GMT
Hello mod_perl 2 users,

I have 3 questions please:

1) How do you specify the path to your custom module,
    so that Apache 2 can load it at the startup?

    I'm using mod_perl-2.0.4-6.el5 with CentOS Linux 5.5 and
    have the following lines in /etc/httpd/conf.d/perl.conf:

    LoadModule perl_module modules/
    Listen 843
    <VirtualHost _default_:843>
        PerlModule                   SocketPolicy
        PerlProcessConnectionHandler SocketPolicy

    but this works only if I put my
    under /etc/httpd. Otherwise it isn't found in @INC.

2) The "perldoc APR:Socket" suggests an example:

         # read from/write to the socket (w/o handling possible failures)
         my $wanted = 1024;
         while ($sock->recv(my $buffer, $wanted)) {

    and later it also says the mod_perl will handle errors for you.

    Shouldn't return values from send() be checked in
    a loop for the cases, that it wasn't able to write the
    complete buffer in 1 pass? Or does send($buffer)
    alsways write the complete $buffer to the blocking socket?

    And what does it mean "mod_perl will handle errors for you"?
    Does it catch exception coming from send()/recv()
    and print it to error_log or is is something else?

3) And the 3rd question is optional (because I'll probably find
    this in the docs soon), but maybe someone can tell me, how
    to log the IP of the socket peer in my module to access_log?

Thank you and below is my module

# cat /etc/httpd/
package SocketPolicy;

# Run: semanage port -a -t http_port_t -p tcp 843
# And add following lines to the httpd.conf
# Listen 843
# <VirtualHost _default_:843>
#       PerlModule                   SocketPolicy
#       PerlProcessConnectionHandler SocketPolicy
# </VirtualHost>

use strict;
use warnings FATAL => 'all';

use Apache2::Connection();
use APR::Socket();

use Apache2::Const(-compile => 'OK');
use APR::Const(-compile => 'SO_NONBLOCK');

use constant POLICY =>
qq{<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM

<allow-access-from domain="*" to-ports="8080"/>

sub handler {
        my $c = shift;
        my $sock = $c->client_socket;

        # set the socket to the blocking mode
        $sock->opt_set(APR::Const::SO_NONBLOCK => 0);




View raw message