Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example in perlbug -f getsockopt incomplete #7797

Closed
p5pRT opened this issue Feb 15, 2005 · 4 comments
Closed

example in perlbug -f getsockopt incomplete #7797

p5pRT opened this issue Feb 15, 2005 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 15, 2005

Migrated from rt.perl.org#34141 (status was 'resolved')

Searchable as RT34141$

@p5pRT
Copy link
Author

p5pRT commented Feb 15, 2005

From david.dyck@fluke.com

Created by david.dyck@fluke.com

The example given in perldoc -f getsockopt​:

  use Socket;

  defined(my $tcp = getprotobyname("tcp"))
  or die "Could not determine the protocol number for tcp";
  # my $tcp = Socket​::IPPROTO_TCP; # Alternative
  my $packed = getsockopt($socket, $tcp, Socket​::TCP_NODELAY)
  or die "Could not query TCP_NODELAY SOCKEt option​: $!";
  my $nodelay = unpack("I", $packed);
  print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n";

is incorrect, it should declare the constant it intends to import
 
I think there is a bug in the documentation that the example may
not get the value of TCP_NODELAY without changing the
  use Socket;
to
  use Socket qw(TCP_NODELAY);
  or
  use Socket qw(​:all);

$ perl -wle 'use Socket; print STDOUT Socket​::TCP_NODELAY'
Socket​::TCP_NODELAY

That was unexpected!!!!!!
either it needs to be called as a function, or imported directly

$ perl -wle 'use Socket; print STDOUT Socket​::TCP_NODELAY()'
1
$ perl -wle 'use Socket; print STDOUT &Socket​::TCP_NODELAY'
1
$ perl -wle 'use Socket qw(TCP_NODELAY); print STDOUT TCP_NODELAY'
1

There is probably a similar error in the alternative use of Socket​::IPPROTO_TCP

I'm not sure why, but the examples use symbols that are in @​EXPORT_OK
and must be imported by the tag :all, or listed explicitly
Not only TCP_NODELAY and IPPROTO_TCP, but also
TCP_KEEPALIVE, TCP_MAXRT, TCP_MAXSEG, TCP_STDURG

There is no mention in the documentation for Socket that suggests
that the user needs to import these symbols. (the :crlf tag IS
documented though)

Perl Info

Flags:
    category=docs
    severity=low

Site configuration information for perl v5.9.2:

Configured by dcd at Mon Feb 14 11:46:39 PST 2005.

Summary of my perl5 (revision 5 version 9 subversion 2 patch 23965) configuration:
  Platform:
    osname=linux, osvers=2.4.30-pre1, archname=i686-linux
    uname='linux dd 2.4.30-pre1 #1 wed feb 9 18:15:26 pst 2005 i686 '
    config_args='-Accflags=-DPERL_DISABLE_PMC -Dmksymlinks -Dinstallusrbinperl -Uversiononly -Dusedevel -Doptimize=-O3 -g -de -Dcf_email=david.dyck@fluke.com'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DPERL_DISABLE_PMC -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O3 -g',
    cppflags='-DPERL_DISABLE_PMC -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='egcs-2.91.66.1 19990314/Linux (egcs-1.1.2 release)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lgdbm -ldbm -ldb -ldl -lm -lc
    perllibs=-ldl -lm -lc
    libc=/lib/libc.so.5.4.44, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    DEVEL22511


@INC for perl v5.9.2:
    /usr/local/lib/perl5/5.9.2/i686-linux
    /usr/local/lib/perl5/5.9.2
    /usr/local/lib/perl5/site_perl/5.9.2/i686-linux
    /usr/local/lib/perl5/site_perl/5.9.2
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.9.2:
    HOME=/home/dcd
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/dcd/bin:/sbin:/usr/local/bin:/bin:/usr/bin:/usr/X11/bin:/usr/games:/usr/local/samba:/home/hobbes/tools/scripts:/home/hobbes/tools/linux:/usr0/hobbes/tools/scripts:/usr0/dcd/bin:/apps/general/bin:/usr/public
    PERL5_CPANPLUS_CONFIG=/home/dcd/.cpanplus/config
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Feb 15, 2005

From @rgs

David Dyck (via RT) wrote​:

The example given in perldoc -f getsockopt​:
...
is incorrect, it should declare the constant it intends to import

I applied the fix below :

==== //depot/perl/pod/perlfunc.pod#453 (text) ====

@​@​ -2115,13 +2115,13 @​@​

An example testing if Nagle's algorithm is turned on on a socket​:

- use Socket;
+ use Socket qw(​:all);

  defined(my $tcp = getprotobyname("tcp"))
  or die "Could not determine the protocol number for tcp";
- # my $tcp = Socket​::IPPROTO_TCP; # Alternative
- my $packed = getsockopt($socket, $tcp, Socket​::TCP_NODELAY)
- or die "Could not query TCP_NODELAY SOCKEt option​: $!";
+ # my $tcp = IPPROTO_TCP; # Alternative
+ my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
+ or die "Could not query TCP_NODELAY socket option​: $!";
  my $nodelay = unpack("I", $packed);
  print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n";

@p5pRT
Copy link
Author

p5pRT commented Feb 15, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Feb 15, 2005

@rgs - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant