getsockopt SOCKET, LEVEL, OPTNAME |
獲取套接字選項SOCKET套接字實現的選項OPTNAME級彆LEVEL。在下表中給出一些的樣例值用於OPTNAME一個套接字級彆
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.
到底在包中的字符串是什麼,取決於LEVEL和OPTNAME, 詳細信息,請谘詢您的係統文檔。
在標量上下文的錯誤返回undef,否則選項值。
試試下麵的例子:如果使用Nagle算法上打開一個socket,這將檢查:
#!/usr/bin/perl #by www.gitbook.net 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";