develooper Front page | perl.perl5.porters | Postings from July 2001

[ID 20010731.099] 5.7.2 win32 select fails on listening socket

Blair Zajac
July 31, 2001 19:07
[ID 20010731.099] 5.7.2 win32 select fails on listening socket
Message ID:

This is a bug report for perl from,
generated with the help of perlbug 1.33 running under perl v5.7.2.

[Please enter your report here]

On 5.7.2 compiled with Visual Studio 6.0 SP5 the following
script cannot successfully call select on an listening
socket.  I've tried this script on 5.7.2 linux, 5.6.1
win32 and Linux and it works fine.

#!/usr/bin/perl -w

$| = 1;

use strict;
use Socket;

# These are the configurable parameters.

# This is the port to listen to.
my $opt_listen_port = 11111;

# Set this to 1 to print verbose messages to standard output.
my $opt_verbose = 1;

# Set up the TCP protocol.
my $proto = getprotobyname('tcp') or
  die "$0: error in getting protocol for tcp: $!\n";

socket(Server, PF_INET, SOCK_STREAM, $proto) or
  die "$0: socket error: $!\n";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) or
  die "$0: setsockopt error: $!\n";
bind(Server, sockaddr_in($opt_listen_port, INADDR_ANY)) or
  die "$0: bind error to port $opt_listen_port: $!\n";
listen(Server, SOMAXCONN) or
  die "$0: listen error: $!\n";

my $fd = fileno(Server);
print "Server on FD $fd\n";
my $rin = '';
vec($rin, $fd, 1) = 1;
my $rout;
my $s = select($rout=$rin, undef, undef, undef);
if ($s == -1) {
  print "Select on Server socket failed ($s): $!\n";
} else {
  print "Select on Server socket succeeded ($s)\n";

for (; my $paddr = accept(Client, Server); close Client) {
  select((select(Client), $| = 1)[0]);

  my ($port, $remote_iaddr) = sockaddr_in($paddr);
  my $remote_ip             = inet_ntoa($remote_iaddr);
  my @remote_ip             = split(/\./, $remote_ip);

  my $remote_name = gethostbyaddr($remote_iaddr, AF_INET);
  if ($remote_name) {
    $remote_name = "name $remote_name";
  } else {
    $remote_name = '';

  # Get the number of seconds since 1970.
  my $time = time;

  my $message = "time $time ip $remote_ip port $port name $remote_name\n";
  print $message if $opt_verbose;
  print Client $message;

[Please do not change anything below this line]
Site configuration information for perl v5.7.2:

Configured by ashleyblair at Mon Jul 30 19:46:03 2001.

Summary of my perl5 (revision 5 undef) configuration:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=undef usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    optimize='-O1 -MD -DNDEBUG',
    ccversion='undef', gccversion='', gccosandvers='undef'
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define, bincompat5005=undef
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release  -libpath:"c:\perl-5.7.2\lib\CORE"  -machine:x86'
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl57.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release  -libpath:"c:\perl-5.7.2\lib\CORE"  -machine:x86'

Locally applied patches:

@INC for perl v5.7.2:

Environment for perl v5.7.2:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=c:\perl-5.7.2\bin;D:\Perl\bin\;C:\Perl\bin\;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program Files\Perforce;C:\ORANT\BIN;C:\Progra~1\MIAF9D~1\VC98\bin;C:\perl-5.7.2\bin;C:\Program Files\Vim\vim56;C:\cygwin\bin;
    PERL_BADLANG (unset)
    SHELL (unset) Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About