Bullock, Howard A. <> wrote:
> In the script example, which I want to be executed as a PDK PerlSvc
> program (Win32 Service), the accept() method is blocking. 
> 
> Is there another module or a technique that I could use to eliminate
> the blocking and have the loop continue so that if the service
> control manager sends a STOP to the service the program will cycle
> back to the PerlSvc ContinueRun function stopping the loop?   
> 
> my $SMTPserver = new Net::SMTP::Server(); while (ContinueRun(1)) {
>    # Place main code or call to main code here
>    my $conn = $SMTPserver->accept();
>    my $client = new Net::SMTP::Server::Client($conn);
>    if (! $client) {
>       WriteLog(LogFileName(), "Error: ABEND: Unable to handle client
> connection: $!");
>    }
>    $client->process;
> }

Net::SMTP::Server (as well as being old - last released in 1999, and not
having great reviews) seems to be no more that a wrapper around an
IO::Socket object. (I can't see the point in that, it just gets in the
way. Deriving from IO::Socket might have been better.) If you create the
IO::Socket directly then you could use IO::Select to time limit the wait
for a connection in your while loop. For example (untested, of course):

my $server = IO::Socket::INET->new(LocalPort => 25, Listen => 1, Reuse
=> 1);
my $sel = IO::Select->new;
$sel->add($server);
my $time_limit = 0.5;
while (ContinueRun(1)) {
    my @fds = $sel->can_read($time_limit);
    if (@fds > 0) {
        my $client = new Net::SMTP::Server::Client($fds[0]->accept());
        ... etc.
    }
}

HTH

-- 
Brian Raven 

=========================================
Atos Euronext Market Solutions Disclaimer
=========================================

The information contained in this e-mail is confidential and solely for the 
intended addressee(s). Unauthorised reproduction, disclosure, modification, 
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message do not 
necessarily reflect those of Atos Euronext Market Solutions.

Atos Euronext Market Solutions Limited - Registered in England & Wales with 
registration no. 3962327.  Registered office address at 25 Bank Street London 
E14 5NQ United Kingdom. 
Atos Euronext Market Solutions SAS - Registered in France with registration no. 
425 100 294.  Registered office address at 6/8 Boulevard Haussmann 75009 Paris 
France.

L'information contenue dans cet e-mail est confidentielle et uniquement 
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. 
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail 
vous parvient par erreur, nous vous prions de bien vouloir prevenir 
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre 
systeme. Le contenu de ce message electronique ne represente pas necessairement 
la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Société de droit anglais, enregistrée au 
Royaume Uni sous le numéro 3962327, dont le siège social se situe 25 Bank 
Street E14 5NQ Londres Royaume Uni.

Atos Euronext Market Solutions SAS, société par actions simplifiée, enregistré 
au registre dui commerce et des sociétés sous le numéro 425 100 294 RCS Paris 
et dont le siège social se situe 6/8 Boulevard Haussmann 75009 Paris France.
=========================================

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to