bbfu has asked for the wisdom of the Perl Monks concerning the following question:

Net::Server is not officially supported on Win32, and it's not listed on CPAN as having passed the tests on Win32. However, the only trouble I had getting it to install under ActiveState Perl was that it used alarm in its test suite. Everything else about the tests appeared to work fine, so I installed it using -force.

So far, everything seems to be working fine, except for two things. I come to the monks now hoping that someone can at least point me in the direction to solving these two issues. Note that both of these problems go away if I run the code under cygwin, or if I use Net::Server::Simple instead of Net::Server::Fork, but there are a few things I want to do that require forking and ActivePerl (specifically, a systray icon and consolessness).

Firstly, it will accept multiple concurrent connections just fine, but the sockets on the second and later concurrent connections don't close when I return from my process_request handler. They don't close until I shut down the server. For my specific application, this will not be an issue but I'm still curious.

Secondly, my program crashes strangely if I try to use a regexp with capturing parens in it. This only happens, however, while processing the next client to connect after the first has disconnected. Multiple clients can connect while the first is still connected and be processed normally (though they then run into the first problem I mentioned). Note, again, that it only occurs when I use the forking personality of Net::Server.

I've include a short piece of code below that demonstrates the problem(s). To test it, run the code, then telnet to the port it reports twice in a row. (ie:

C:\> telnet localhost 20203 C:\> telnet localhost 20203
)

I'm probably going to try converting the test case over to a handle the sockets and forking manually (ie, remove Net::Server) to see if the problem is there or somewhere in Net::Server. Please, any ideas or suggestions on where else to look, or another approach to try, are welcome!

Sample code:

#!/usr/bin/winperl use warnings; use strict; use base 'Net::Server'; sub process_request { print "Hello.\r\n"; warn "Foo.\n"; # This line causes an error dialog to pop up with the # following message under Win2k: # The instruction at "0x28073fc9" referenced memory at "0x01fc2da0 +". # The memory could not be "read". "string" =~ /(.)/; warn "Got $1\n"; sleep 10; print "Goodbye.\r\n"; } # Auto-flush STDOUT and STDERR my $old = select(STDOUT); $|=1; select(STDERR); $|=1; select($old); # Start the server main->run();

Perl version:

This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2001, Larry Wall

Binary build 633 provided by ActiveState Corp. http://www.ActiveState.com
Built 21:33:05 Jun 17 2002

bbfu
Black flowers blossom
Fearless on my breath

update (broquaint): added <readmore>

Replies are listed 'Best First'.
Re: Net::Server::Fork on Win32: Memory access error on pattern match
by Jenda (Abbot) on Apr 08, 2003 at 12:48 UTC

    You can get rid of the console even with the Cygwin perl. See this. I don't have any idea how to make the systray icon with that perl though.

    The regexp problem might be solved by updating to Perl 5.8. The fork() creates threads under Windows (at least the normal port. I know next to nothing about cygwin) and the interpreter threads were not very stable in Perl 5.6.

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

      Yeah, I kind of figured it was an issue with fork being emulated with threads, but I was thrown off and confused by the fact that it worked fine as long as the connections were all concurrent and the fact that the problem didn't arise if sockets weren't involved.

      As it turns out, you were correct. The issue was some sort of interaction between sockets and the fork emulation that aggrivated the bug in the regexp engine mentioned explicitly in perldoc perlfork (not sure why I didn't think to check there originally). Upgrading to 5.8.1 fixed it completely (both issues, actually).

      Thanks!

      bbfu
      Black flowers blossom
      Fearless on my breath