首页 > 编程语言 >无涯教程-Perl - getsockopt函数

无涯教程-Perl - getsockopt函数

时间:2023-08-10 13:31:43浏览次数:46  
标签:status getsockopt Get 无涯 tcp Perl SO TCP Socket

描述

此函数获取optionsOPTNAME在Socket实现级别LEVEL上在SOCKET上设置的Socketoptions。下表提供了一些OPTNAME在Socket级别的示例值-

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,有关详细信息,请查阅系统文档。

语法

以下是此函数的简单语法-

getsockopt SOCKET, LEVEL, OPTNAME

返回值

此函数在错误时返回undef,否则返回标量context中的options值。

以下是显示其基本用法的示例代码,这将检查Nagle的算法是否在Socket上打开。但是,在此示例中,您将必须打开一个Socket以提供存储的ID-

#!/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";

参考链接

https://www.learnfk.com/perl/perl-getsockopt.html

标签:status,getsockopt,Get,无涯,tcp,Perl,SO,TCP,Socket
From: https://blog.51cto.com/u_14033984/7033943

相关文章

  • 无涯教程-Perl - getprotoent函数
    描述此函数返回有效协议列表中的下一个条目:($name,$aliases,$protocol_number)语法以下是此函数的简单语法-getprotoent返回值此函数针对错误返回undef,否则返回标量context中的协议编号,并在列表context中返回错误协议记录的空列表(名称,别名,协议编号)。例以下是显......
  • 无涯教程-Perl - getprotobynumber函数
    描述此函数在标量context中将协议NUMBER转换为其对应的名称,在列表context中将其名称和相关信息转换为:($name,$aliases,$protocol_number)。语法以下是此函数的简单语法-getprotobynumberNUMBER返回值此函数针对错误返回undef,否则返回标量context中的协议编号,并在列......
  • 无涯教程-Perl - getpriority函数
    描述此函数返回进程(PRIO_PROCESS),进程组(PRIO_PGRP)或用户(PRIO_USER)的当前优先级。参数WHICH指定要为PRIO_PROCESS,PRIO_PGRP或PRIO_USER之一设置优先级的实体,WHO是要设置的进程ID或用户ID。WHO的值为0定义了当前流程,流程组或用户。这会在不支持系统getpriority()函数的......
  • 正则表达式(Perl风格)
    1、修饰符修饰符描述i完成不区分大小写的搜索g查找所有出现(alloccurrences,完成全局搜索)m将一个字符串视为多行(m就标识多multiple)。默认情况下,^和$字符串匹配字符串中的最开始和最末尾。使用m修饰符将使^和$匹配字符串中每行的开始s将一个字符串视为一行,忽略其中的......
  • 无涯教程-Perl - getnetbyaddr函数
    描述此函数返回ADDR指定的网络信息,并在列表context中键入ADDRTYPE:($name,$aliases,$addrtype,$net)语法以下是此函数的简单语法-getnetbyaddrADDR,ADDRTYPE返回值此函数在错误时返回undef,否则在标量context中返回网络地址,在错误时返回空列表,否则在列表context中返......
  • perl通过unixODBC连接SQLServer
    本文讲述三个内容:一:说明二:环境配置三:操作脚本内容一:说明MS从来没有提供过SQLServerforLinux,所以大家也不要去尝试在Linux系统安装SQLServer,但是可以通过ODBC连接Windows系统的SQLServer数据库;WindowsServer2003用户注意:在WindowsServer2003系统上安装的SQLServer是不......
  • perl基本语言语法(与java,c#不同的地方积累)
    连接字符串 perl用.  “hello”+"hello" 可用x号 "hello"*3 “hellohellohello”java,c#用+"hello"+"hello"运算符perl等待输入:$line=<STDIN>;或者$line=<>;未定义的字符值undef--不会报错当作数字使用时为0当作字符串使用时为空判断是否为空用defined()数组......
  • HandlerSocket的perl接口操作方法
    实例化:/*   *String $host:MySQLip;  *String $port:handlersocket插件的监听端口,它有两个端口可选:一个用于读、一个用于写   */ $hs=newHandlerSocket($host,$port);运用例子:#9998为读取端口详见上一篇handlersocket的安装my$args={host=>'loca......
  • 无涯教程-Perl - getgrnam函数
    描述此功能通过组名查找组文件条目。在列表context中返回以下内容-($name,$passwd,$gid,$members)$members标量包含作为组成员的登录名的空格分隔列表。在标量context中返回组名。有关检索整个组文件的更有效方法,请参阅getgrent。在Windows下,请考虑使用Win32API::Net模块。......
  • 无涯教程-Perl - format函数
    如前所述,Perl代表实用提取和报告语言,我们现在将讨论使用Perl编写报告。Perl使用称为"格式"的书写模板来输出报告。要使用Perl的格式功能,您必须-定义格式PassthedatathatwillbedisplayedontheformatInvoketheFormat定义格式以下是定义Perl格式的语法format......