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

Esteemed Monks,

I developed a project in Linux, using among the others IO::Socket and Log::Log4perl. All fine. I then tried to put the same code in Windows using ActiveState Perl 5.8.8.817, but with much less luck. In the most weird way.

I saw the following error:

2006/07/03 16:19:06 IO::Socket::INET::new(): IO::Socket::INET: No such + file or directory at notifyd.pl line 229
so I said "aha! I'll isolate a little script to show there on PerlMonks!", and I isolated the offending code as follows:
#!/usr/bin/perl use strict; use warnings; use IO::Socket; use Log::Log4perl qw( :easy ); #Log::Log4perl->easy_init($DEBUG); # NOTE: COMMENTED HERE my %listener_parameters = ( Proto => 'udp', Blocking => 1, ReuseAddr => 1, ); my $listener = new IO::Socket::INET(%listener_parameters) or die "IO::Socket::INET::new(): '$@'"; __END__ C:\Documents and Settings\Administrator\Desktop\mms>perl case.pl IO::Socket::INET::new(): 'IO::Socket::INET: ' at case.pl line 13.
Note that Log::Log4perl->easy_init($DEBUG); is commented here - I'm using die - and ARGH! The code is obviously continuing to offend, but it has another message! Well, in the first shot I was using Log4perl, right? Let's restore it:
#!/usr/bin/perl use strict; use warnings; use IO::Socket; use Log::Log4perl qw( :easy ); Log::Log4perl->easy_init($DEBUG); # RESTORED LINE my %listener_parameters = ( Proto => 'udp', Blocking => 1, ReuseAddr => 1, ); my $listener = new IO::Socket::INET(%listener_parameters) or die "IO::Socket::INET::new(): '$@'"; __END__ C:\Documents and Settings\Administrator\Desktop\mms>perl case.pl IO::Socket::INET::new(): 'IO::Socket::INET: Bad file descriptor' at ca +se.pl line 13.
ARARGH! With the only call to easy_init() the error message has changed another time! The errors seem to be kind of consistent: each different version of the script always produces the same error message, but apart from this...

Please save me from this hell: what's going on?

Update: I'm using the indirect call notation here, but only because I tried all the flavours given the initial message of "No such file or directory". In my actual code I'm using IO::Socket::INET->new(%listener_parameters).

Update 2: I managed to eliminate the errors and get the UDP socket to work by eliminating the Blocking => 1 configuration. This is extremely weird, given the fact that this blocking behaviuour should be the default, and that I included it only for paranoic reasons.

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

Replies are listed 'Best First'.
Re: Complete mess with IO::Socket in ActivePerl 5.8.8.817
by traveler (Parson) on Jul 03, 2006 at 21:07 UTC
    UDP sockets don't block. It seems Win32 (or at least the perl you are using on Win32) doesn't, therefore, allow setting that attribute. Also, I tried your code and tried to use fcntl to check the blocking status of the socket. It seems that ActiveState has not defined the O_NONBLOCK value, at least not in 5.8.1.
      UDP sockets don't block.
      It actually seems that they don't nonblock in Win32, don't they? :) Thank you for the time and effort traveler.

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Don't fool yourself.
        You are right. The default behavior in Windows is to block. However, it appears that this is not really a block for 16-bit apps as the message loop stays running, so the code can be re-entered somewhere else. However 32-bit apps hang the UI... Pretty interesting.