develooper Front page | perl.perl5.porters | Postings from May 2004

Proposed doc patch for getsockopt

Thread Next
From:
perl5-porters
Date:
May 16, 2004 06:36
Subject:
Proposed doc patch for getsockopt
Message ID:
c87qmo$u9b$1@post.home.lunix
I think the getsockopt entry in perlfunc is a bit unclear since it 
seems to suggest it directly returns the option value, while in 
reality it returns a packed structure. And it could use some fleshing 
out anyways. Proposed new text:

getsockopt SOCKET,LEVEL,OPTNAME
    getsockopt queries the option named OPTNAME associated with 
    SOCKET at a given LEVEL. Options may exist at multiple protocol
    levels depending on the socket type, but at least the uppermost
    socket level SOL_SOCKET (defined in the Socket module) will 
    exist. To query options at another level the protocol number of 
    the appropriate protocol controlling  the  option  should be 
    supplied.  For example, to indicate that an option is to be 
    interpreted by the TCP protocol, LEVEL should be set to the 
    protocol number of TCP, which you can get using getprotobyname.

    The call returns a packed string representing the requested socket 
    option, or undef if there is an error (the error reason will be in $!).
    What exactly is in the packed string depends in the LEVEL and 
    OPTNAME, consult your system documentation for details. A very common
    case however is that the option is an integer, in which case the
    result will be an packed integer which you can decode using unpack
    with the "i" (or "I") format.

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

        use Socket;

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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About