perl - 如何使用 IO::Select 阻止等待读取或写入套接字?

标签 perl sockets networking

我正在使用IO::Select .

它是 normal select call 的 OOP 包装器,但它公开了 can_read()can_write() 方法。有没有办法阻止等待读或写套接字?这不是(几乎)违背了 IO::Select 的初衷吗?

最佳答案

使用IO::Select->select :

select ( READ, WRITE, EXCEPTION [, TIMEOUT ] )

select is a static method, that is you call it with the package name like new. READ, WRITE and EXCEPTION are either undef or IO::Select objects. TIMEOUT is optional and has the same effect as for the core select call.

The result will be an array of 3 elements, each a reference to an array which will hold the handles that are ready for reading, writing and have exceptions respectively. Upon error an empty list is returned.

例如:

my $rsel  = IO::Select->new($rfh);
my $wsel  = IO::Select->new($wfh);
my $esel  = IO::Select->new($rfh, $wfh);

my @ready = IO::Select->select($rsel, $wsel, $esel, undef);

关于perl - 如何使用 IO::Select 阻止等待读取或写入套接字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42151567/

相关文章:

perl - B::Lint 和 Perl::Critic 用于静态代码分析

regex - 珀尔。正则表达式只工作一次

perl - 如何使用 ExtUtils::MakeMaker 在 META 文件中填充 'provides' 字段

perl - 为什么在 perl one liner 中以 slurp 模式使用 -p|-n ?

C# TCP Socket编程——向所有套接字发送数据

c++ - 多线程多套接字同时发送/接收

java - 使用 readDouble 从套接字输入读取 Double + EOL

c++ - 如何获取直接连接到我的PC的计算机的IP地址

c# - 如何监控以太网连接状态

networking - ping 响应是否包含 MAC 地址?