Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 10987 invoked from network); 21 Oct 2010 14:48:23 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 Oct 2010 14:48:23 -0000 Received: (qmail 44089 invoked by uid 500); 21 Oct 2010 14:48:22 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 43984 invoked by uid 500); 21 Oct 2010 14:48:20 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 43977 invoked by uid 99); 21 Oct 2010 14:48:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Oct 2010 14:48:19 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [72.45.166.182] (HELO mail2.livesite.net) (72.45.166.182) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Oct 2010 14:48:11 +0000 Received: from localhost (localhost [127.0.0.1]) by mail2.livesite.net (Postfix) with ESMTP id A64E6314EA4; Thu, 21 Oct 2010 10:47:49 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at livesite.net Received: from mail2.livesite.net ([127.0.0.1]) by localhost (mail2.livesite.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 63GYzMIvZ-1i; Thu, 21 Oct 2010 10:47:46 -0400 (EDT) Received: from devbox.lsnllc (rrcs-72-45-166-178.nys.biz.rr.com [72.45.166.178]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail2.livesite.net (Postfix) with ESMTPSA id 89478314E08; Thu, 21 Oct 2010 10:47:46 -0400 (EDT) Message-ID: <4CC052F1.3050200@livesite.net> Date: Thu, 21 Oct 2010 10:49:21 -0400 From: Ryan Gies Organization: Livesite Networks, LLC User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.12) Gecko/20100907 Fedora/3.0.7-1.fc12 Lightning/1.0b1 Thunderbird/3.0.7 MIME-Version: 1.0 To: Alexander Farber CC: modperl@perl.apache.org Subject: Re: Path to my module and APR::Socket::send() usage References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On 10/21/2010 08:35 AM, Alexander Farber wrote: > 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? > To adjust @INC at start-up: PerlSwitches -I /my/perl/lib Or, you can run a perl script at startup (which contains the "use lib '/my/perl/lib';"): PerlRequire /my/startup.pl See also: http://perl.apache.org/docs/2.0/user/config/config.html#Adjusting_C__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)) { > $sock->send($buffer); > } > > 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? > No idea... > 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? > Something else: if your module dies, mod_perl will send an error document and set the status code for the response. > 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 > Alex > > # cat /etc/httpd/SocketPolicy.pm > package SocketPolicy; > > # Run: semanage port -a -t http_port_t -p tcp 843 > # And add following lines to the httpd.conf > # Listen 843 > # > # PerlModule SocketPolicy > # PerlProcessConnectionHandler SocketPolicy > # > > 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{ > "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> > > > > > \0}; > > 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); > > $sock->send(POLICY); > > Apache2::Const::OK; > } > > 1; >