Funzione Perl getsockopt
Descrizione
Questa funzione ottiene le opzioni del socket impostate su SOCKET al livello di implementazione del socket LEVEL per l'opzione OPTNAME. Alcuni valori di esempio per OPTNAME a livello di socket sono forniti nella tabella seguente:
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. 
    Cosa c'è esattamente nella stringa compressa dipende da LEVEL e OPTNAME, consultare la documentazione del sistema per i dettagli.
Sintassi
Di seguito è riportata la semplice sintassi per questa funzione:
getsockopt SOCKET, LEVEL, OPTNAME 
    Valore di ritorno
Questa funzione restituisce undef in caso di errore altrimenti il valore dell'opzione in contesto scalare.
Esempio
Di seguito è riportato il codice di esempio che mostra il suo utilizzo di base, questo controllerà se l'algoritmo di Nagle è attivato su un socket. Ma qui dovresti aprire un socket per fornire l'ID socked in questo esempio -
#!/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"; 
                        