- Perl Basics
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
- Perl - Operators
- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl Advanced
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Useful Resources
- Perl - Discussion
Perl getsockopt Function
Description
This function gets the socket options set on SOCKET at the socket implementation level LEVEL for the option OPTNAME. Some sample values for OPTNAME at a socket level are given in Table below −
OPTNAME Result SO_DEBUG Get status of recording of debugging information SO_REUSEADDR Get status of local address reuse SO_KEEPALIVE Get status of keep connections alive SO_DONTROUTE Get status of routing bypass for outgoing messages SO_LINGER Get status of linger on close if data is present SO_BROADCAST Get status of permission to transmit broadcast messages SO_OOBINLINE Get status of out-of-band data in band SO_SNDBUF Get buffer size for output SO_RCVBUF Get buffer size for input SO_TYPE Get the type of the socket SO_ERROR Get and clear error on the socket TCP_NODELAY To disable the Nagle buffering algorithm.
What exactly is in the packed string depends in the LEVEL and OPTNAME, consult your system documentation for details.
Syntax
Following is the simple syntax for this function −
getsockopt SOCKET, LEVEL, OPTNAME
Return Value
This function returns undef on error otherwise option value in scalar context.
Example
Following is the example code showing its basic usage, this will check if Nagle's algorithm is turned on on a socket. But, here you would have to open one socket to provide socked ID in this example −
#!/usr/bin/perl use Socket qw(:all); defined(my $tcp = getprotobyname("tcp")) or die "Could not determine the protocol number for tcp"; # 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";
perl_function_references.htm
Advertisements