I posted this on the PDK mailing list but only got one reply. I'd like a 2nd opinion before I re-code!
Thanks, Lee (post, other reply & dialog follows) > -----Original Message----- > From: Lee Clemmer [mailto:[EMAIL PROTECTED]] > Sent: Thursday, December 19, 2002 2:41 PM > To: '[EMAIL PROTECTED]' > Subject: Perlsvc created a program that eternally says "starting" > > > I've made my first PerlSvc service. In the past I've used > SRVANY from the NT resource kit and had no problems. > > The program .exe gets built with no errors, and the install > works (although I've got a question about that). > > My problem is when attempting to start the service, the > dialog shows that blue bar creeping across > very...very...slowly. Eventually it times out and notes that > the service did not respond to the control function before > timing out. HOWEVER the service is running and functioning > properly! It's listening on its TCP port, wrote to the event > log that it started, accepts connections and updates the > event log, etc. > > But of course the services panel still shows "Starting" > giving NO WAY to stop, pause, or otherwise manipulate the > service's state! > > What gives here? > > Is this code set up wrong? (code below) Note that some of the > bits are 'leftovers' from running it as a command line exe. > If they are problematic I'd like to know and remove 'em. Is > the $SIG{INT} thing a problem? > --------------------Code follows-------------------------------- > #!/bin/perl > package PerlSvc; > $Name = 'MyService'; > $DisplayName = 'Lee's Service'; > > sub Startup { > while (ContinueRun(5)) { > main(); > } > } > sub Help { > print "Some relevant help text\n"; > } > package main; > > # The program... defines, stuff, etc... > > #use strict; > #use diagnostics; > use IO::Socket qw(:DEFAULT :crlf); > use IO::Socket::INET; > use IO::Handle; > use IO::Select; > use Win32::TieRegistry; > use Win32::EventLog; > > use Carp; > $Registry->Delimiter("/"); > my ($scalars,@arrays,$lotsofstuff); > my $logfile = "c:/log.txt"; > $lport = '4321'; > $/ = CRLF; > > if ($ARGV[0]) { $debug = shift(@ARGV) } else { $debug = 0}; > > # Catch the interrupt ^C signal > $SIG{INT} = sub { $quit++ }; > > # next we set up log stuff, etc. > #...<snip> > #...then we call a socket subroutine and set up a listener... > sub socket { > my $port = $_[0]; > my $sock = IO::Socket::INET->new( Listen=> 20, > LocalPort => $port, > Timeout => 2, > Reuse => 1) > or die "Can't create listening socket: $!\n"; > $sock->autoflush(); > warn "\nwaiting for incoming connections on port $port...\n"; > print LOG "waiting for incoming connections on port $port...\n"; > while (!$quit) { > next unless my $session = $sock->accept; > $peer = > gethostbyaddr($session->peeraddr,AF_INET) || $session->peerhost; > my $peerport = $session->peerport; > my $time1 = localtime; > print LOG "Connection to port $port from > [$peer,$peerport] started at $time1\n"; > warn "Connection from [$peer,$peerport]\n"; > while (<$session>) { > chomp; > # other stuff...<snip> > } > } > #and that's pretty much it. > -------------------------------Code Ends---------------------------------- > > Thanks for any help! > > Lee > Howard said: I believe that this statement (my $session = $sock->accept;) is blocking and your ContinueRun loop doesn't process for the first time until you actually get some input on the port. Look into: my $select = new IO::Select(); $select->add($HTTPd); # add the listen socket to the select mask my $sel_int = .250; my ($oConn,$ConnData); my ($port, $iaddr); my $hostname; my $myipaddr; while (ContinueRun()) { my @ready = $select->can_read($sel_int); foreach my $endpt (@ready) { if ($endpt == $HTTPd) { ($oConn,$ConnData) = $HTTPd->accept; print "loop " . time ."\n"; ($port, $iaddr) = sockaddr_in ($ConnData); $hostname = gethostbyaddr ($iaddr, AF_INET); $myipaddr = inet_ntoa ($iaddr); } My guess is that the "next" will never process because the program is waiting to receive input. -----Original Message----- From: Lee Clemmer [mailto:[EMAIL PROTECTED]] Sent: Friday, December 20, 2002 9:12 AM To: Bullock, Howard A.; [EMAIL PROTECTED] Subject: RE: Perlsvc created a program that eternally says "starting" Thanks for the reply. So, even with this line: next unless my $session = $sock->accept; in the subroutine loop, we're not completing the first ContinueRun loop? Thanks for the/any clarification, Lee _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs