perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Farber <alexander.far...@gmail.com>
Subject Re: Path to my module and APR::Socket::send() usage
Date Thu, 21 Oct 2010 16:38:06 GMT
Even though my logs show that 1 send-call usually suffices
(I have a site with 1 visitor/3 min), I've updated my script.

Not sure if returning DECLINED is a good idea.

And if you know a way to log into access_log
instead of error_log, please tell me.

Thank you
Alex


package SocketPolicy;

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

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

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

use constant POLICY =>
qq{<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>
<allow-access-from domain="*" to-ports="8080"/>
</cross-domain-policy>
\0};

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

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

        do {
                my $nbytes = $sock->send(substr(POLICY, $offset),
length(POLICY) - $offset);
                # client connection closed or interrupted
                return Apache2::Const::DECLINED unless $nbytes;
                $offset += $nbytes;
        } while ($offset < length(POLICY));

        my $slog = $c->base_server()->log();
        $slog->warn('served socket policy to: ', $c->remote_ip());

        return Apache2::Const::OK;
}

1;

Mime
View raw message