Movatterモバイル変換


[0]ホーム

URL:


functions /getsockopt
(source,CPAN)
You are viewing the version of this documentation from Perl 5.42.0-RC3. This is a development version of Perl.
#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 socket type, but at least the uppermost socket level SOL_SOCKET (defined in theSocket 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 usinggetprotobyname.

The function returns a packed string representing the requested socket option, orundef on error, with the reason for the error placed in$!. Just what is in the packed string depends on LEVEL and OPTNAME; consultgetsockopt(2) for details. A common case is that the option is an integer, in which case the result is a packed integer, which you can decode usingunpack with thei (orI) format.

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

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

Portability issues:"getsockopt" in perlport.

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp