Fellow monks,
I fear I'm missing something obvious, but for the life of me I can't figure it out. The code below is the minimal case for what I'm trying to do. $Socket->connected doesn't return false when I'm disconnected unless I try to send further data to the other side of the connection. It just keeps reading empty strings from the socket (which, without blocking on, is exactly the same as being connected but not having data on the line). However, when I use netstat, it says that the connection is quite clearly closed. I need the while loop to exit when I'm disconnected, as is expected. What am I doing wrong?

Here's the code...

#!/usr/bin/perl use warnings; use strict; use IO::Socket::INET; my $Socket = IO::Socket::INET->new(PeerAddr=>"perlmonks.org:80") or di +e; $Socket->send("GET /404 HTTP/1.0$/$/") or die; while ($Socket->connected) { $Socket->recv(my($Byte),1); if (length($Byte)) { print "Byte: $Byte$/"; } else { print "No byte.$/"; } }

Here's perl -V:

Summary of my perl5 (revision 5.0 version 8 subversion 1) configuratio +n: Platform: osname=linux, osvers=2.4.21-1.1931.2.307.entbigmem, archname=i386- +linux-thread-multi uname='linux bugs.devel.redhat.com 2.4.21-1.1931.2.307.entbigmem # +1 smp sat jul 5 11:55:51 edt 2003 i686 i686 i386 gnulinux ' config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 - +Dversion=5.8.0 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc +=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchn +ame=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Dotherlibdirs=/ +usr/lib/perl5/5.8.1 -Duseshrplib -Dusethreads -Duseithreads -Duselarg +efiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shado +w -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompa +t5005 -Uversiononly -Dpager=/usr/bin/less -isr' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemulti +plicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS + -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_S +OURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm', optimize='-O2 -g -pipe -march=i386 -mcpu=i686', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGI +NG -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm' ccversion='', gccversion='3.3 20030623 (Red Hat Linux 3.3-12)', gc +cosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.s +o gnulibc_version='2.3.2' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynami +c -Wl,-rpath,/usr/lib/perl5/5.8.1/i386-linux-thread-multi/CORE' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS USE_LARGE_ +FILES PERL_IMPLICIT_CONTEXT Locally applied patches: RC2 Built under linux Compiled at Jul 11 2003 23:02:08 @INC: /usr/lib/perl5/5.8.1/i386-linux-thread-multi /usr/lib/perl5/5.8.1 /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.1/i386-linux-thread-multi /usr/lib/perl5/5.8.1 .

-BronzeWing


You are in a maze of twisty little knowledge base documents, all alike.
It is dark. You are likely to be eaten by a lawyer.


In reply to $Socket->connected Not Returning False? by BronzeWing

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.