Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Retrieve the sockaddr for a gi ...Register your socket as a server (Berikutnya)
Low-level socket functions

Get socket options on a given socket

Daftar Isi

  • getsockopt SOCKET,LEVEL,OPTNAME

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

    The function returns a packed string representing the requested socketoption, or undef on error, with the reason for the error placed in$!. Just what is in the packed string depends on LEVEL and OPTNAME;consult getsockopt(2) for details. A common case is that the option is aninteger, in which case the result is a packed integer, which you can decodeusing unpack with the i (or I) format.

    Here's an example to test whether Nagle's algorithm is enabled on a socket:

    1. use Socket qw(:all);
    2. defined(my $tcp = getprotobyname("tcp"))
    3. or die "Could not determine the protocol number for tcp";
    4. # my $tcp = IPPROTO_TCP; # Alternative
    5. my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
    6. or die "getsockopt TCP_NODELAY: $!";
    7. my $nodelay = unpack("I", $packed);
    8. print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n";

    Portability issues: getsockopt in perlport.

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Retrieve the sockaddr for a gi ...Register your socket as a server (Berikutnya)