From: brandon on
On Jan 16, 4:22 pm, Uri Guttman <u...(a)stemsystems.com> wrote:
> >>>>> "b" == brandon  <brandon.mayfi...(a)att.net> writes:
>
>   >> After a successful system call, $! contains whatever it contained
>   >> *before* that system call.  Looking in $! is meaningful only after
>   >> an unsuccessful system call.
>   >>
>
>   b>  Yes, and note from the code I did test it before and set it to '0'.
>
> but you are missing the point. if the call to IO::Socket->new doesn't
> return undef, there is NO point in checking out $! or $@. they will be
> meaningless and may be set to some irrelevant value. i have never had to
> clear those before making any lib or system calls. i only check them if
> there is an indicator of an error. checking them directly is wrong in
> almost every case. they could be changed due to some internal call that
> is redone or worked around and yet your call will still have succeeded.
>

But I do understand. The call is failing on port 10, I am not getting
a socket because there is no listening process on port 10. Some of the
platforms are working (Linux and Sun) and some are not (AIX and HP).
My code does check to see if the call to new() failed, I just threw in
the print's to see what it is set to in all cases as some additional
debug. I did not put those print's in until after I noticed that I was
getting strange perrors went the call failed as I expected it to.

> uri
>
> --
> Uri Guttman  ------  u...(a)stemsystems.com  --------  http://www.sysarch.com--
> -----  Perl Architecture, Development, Training, Support, Code Review  ------
> -----------  Search or Offer Perl Jobs  -----http://jobs.perl.org ---------
> ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com---------

From: brandon on
I'll make the example even simpler :-) The only reason I'm printing
$! and $@ before the call is even made is to prove that errno IS
getting
set.

----------------------------------------------------------
#!/usr/bin/perl

use IO::Socket;
use strict;

my($server_ip, $server_port) = ("172.16.18.96", "10");
my($timeout) = 5;
my($socket);

print "\$! = $!\n";
print "\$@ = $@\n";

$socket = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => $server_ip,
PeerPort => $server_port,
Timeout => $timeout
);

if ( $socket ) {
close $socket;
print " OK : Port $server_port is OPEN\n";
exit 1;
}

# else
# Other error detected
print "\$! = $!\n";
print "\$@ = $@\n";
exit 0;
-------------------------------------------------------------

# uname -rvs
AIX 3 5
# perl -v

This is perl, v5.8.2 built for aix-thread-multi
(with 2 registered patches, see perl -V for more detail)

Copyright 1987-2003, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source
kit.

Complete documentation for Perl, including FAQ lists, should be found
on
this system using `man perl' or `perldoc perl'. If you have access to
the
Internet, point your browser at http://www.perl.com/, the Perl Home
Page.

# ./simple.pl
$! =
$@ =
$! = A system call received a parameter that is not valid.
$@ = IO::Socket::INET: connect: A system call received a parameter
that is not valid.
#

I should have gotten : "A remote host refused an attempted connect
operation."

# telnet 172.16.18.96 10
Trying...
telnet: connect: A remote host refused an attempted connect operation.
#


From: Uri Guttman on
>>>>> "b" == brandon <brandon.mayfield(a)att.net> writes:

b> On Jan 16, 4:22�pm, Uri Guttman <u...(a)stemsystems.com> wrote:
>> >>>>> "b" == brandon �<brandon.mayfi...(a)att.net> writes:
>>
>> � >> After a successful system call, $! contains whatever it contained
>> � >> *before* that system call. �Looking in $! is meaningful only after
>> � >> an unsuccessful system call.
>> � >>
>>
>> � b> �Yes, and note from the code I did test it before and set it to '0'.
>>
>> but you are missing the point. if the call to IO::Socket->new doesn't
>> return undef, there is NO point in checking out $! or $@. they will be
>> meaningless and may be set to some irrelevant value. i have never had to
>> clear those before making any lib or system calls. i only check them if
>> there is an indicator of an error. checking them directly is wrong in
>> almost every case. they could be changed due to some internal call that
>> is redone or worked around and yet your call will still have succeeded.
>>

b> But I do understand. The call is failing on port 10, I am not getting
b> a socket because there is no listening process on port 10. Some of the
b> platforms are working (Linux and Sun) and some are not (AIX and HP).
b> My code does check to see if the call to new() failed, I just threw in
b> the print's to see what it is set to in all cases as some additional
b> debug. I did not put those print's in until after I noticed that I was
b> getting strange perrors went the call failed as I expected it to.

but you still don't get it. clearing error variables before the call or
printing them in all cases is useless. i repeat useless. it is not extra
debugging info but random noise. only if the new call FAILS do some of
the error vars have meaning. and $! will still be meaningless as you
don't know what internal system calls were made and if their failures
mean anything. so printing them at any time unless you make a direct
system call is useless. i repeat useless. just noise.

only print error values when you actually have an error. you detect
errors from io::socket::new by its return value. period. all preprinting
is useless. all error postprinting without an actuall error is useless.

do you understand me now??

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Uri Guttman on
>>>>> "b" == brandon <brandon.mayfield(a)att.net> writes:

b> I'll make the example even simpler :-) The only reason I'm printing
b> $! and $@ before the call is even made is to prove that errno IS
b> getting
b> set.

useless as you don't know what system calls were made and which ones may
have failed.

b> ----------------------------------------------------------
b> #!/usr/bin/perl

b> use IO::Socket;
b> use strict;

b> my($server_ip, $server_port) = ("172.16.18.96", "10");
b> my($timeout) = 5;
b> my($socket);

declare variables when first used. no need for the () in the scalar cases

b> print "\$! = $!\n";
b> print "\$@ = $@\n";

useless noise. no information

b> $socket = IO::Socket::INET->new(

my $socket = ....

b> Proto => "tcp",
b> PeerAddr => $server_ip,
b> PeerPort => $server_port,
b> Timeout => $timeout
b> );

b> if ( $socket ) {
b> close $socket;
b> print " OK : Port $server_port is OPEN\n";
b> exit 1;
b> }

b> # else
b> # Other error detected
b> print "\$! = $!\n";

useless as the module makes MANY system calls and you may not know which
one failed. $! is only useful on YOUR DIRECT system call.

b> print "\$@ = $@\n";
b> $! =
b> $@ =

see, useless noise.

b> $! = A system call received a parameter that is not valid.

useless error message.
b> $@ = IO::Socket::INET: connect: A system call received a parameter
b> that is not valid.
b> #

b> I should have gotten : "A remote host refused an attempted connect
b> operation."

perl -MIO::Socket -e '$s = IO::Socket::INET->new( "127.0.0.1:1234"); print "$@\n" unless $s'
IO::Socket::INET: connect: Connection refused

perl -MIO::Socket -e '$s = IO::Socket::INET->new( "172.16.18.96:1234"); print "$@\n" unless $s'
IO::Socket::INET: connect: Connection timed out


neither of those is what you expected so your expectations were
wrong. the telnet program is not IO::Socket.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: brandon on
Just for grins I just now built perl 5.8.8 on an AIX 5.3 box :

# uname -svr
AIX 3 5
# /home/brandonm/perl-5.8.8/perl -v

This is perl, v5.8.8 built for aix

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source
kit.

Complete documentation for Perl, including FAQ lists, should be found
on
this system using "man perl" or "perldoc perl". If you have access to
the
Internet, point your browser at http://www.perl.org/, the Perl Home
Page.

# /home/brandonm/perl-5.8.8/perl -e 'print "@INC\n";'
/opt/lib/perl5/5.8.8/aix /opt/lib/perl5/5.8.8 /opt/lib/perl5/site_perl/
5.8.8/aix /opt/lib/perl5/site_perl/5.8.8 /opt/lib/perl5/site_perl .
# for i in `/home/brandonm/perl-5.8.8/perl -e 'print "@INC\n";'` ; do
find $i -name Socket.pm ; done
/opt/lib/perl5/5.8.8/aix/Socket.pm
/opt/lib/perl5/5.8.8/aix/IO/Socket.pm
/opt/lib/perl5/5.8.8/aix/Socket.pm
/opt/lib/perl5/5.8.8/aix/IO/Socket.pm
# /home/brandonm/perl-5.8.8/perl ./simple.pl
$! =
$@ =
$! = A system call received a parameter that is not valid.
$@ = IO::Socket::INET: connect: A system call received a parameter
that is not valid.
#

I removed the shebang line from the sample code so I would be sure to
get the new perl interpreter and modules.