Perl的 - 的Win32 - 如何做从其他处理的文件句柄的非阻塞读? [英] Perl - Win32 - How to do a non-blocking read of a filehandle from another process?
问题描述
我在写一些服务器code,它通过标准输入会谈到客户端进程。我试着写的perl code异步从客户端的STDOUT接收响应的一个片段。在code的阻塞版本可能是这样的:
I'm writing some server code that talks to a client process via STDIN. I'm trying to write a snippet of perl code that asynchronously receives responses from the client's STDOUT. The blocking version of the code might look like this:
sub _read_from_client
{
my ($file_handle) = @_;
while (my $line = <$file_handle>) {
print STDOUT $line;
}
return;
}
重要的是,片段需要Win32平台上工作。有对* nix平台许多解决方案,我没兴趣。我使用的ActivePerl 5.10。
Importantly, the snippet needs to work in Win32 platform. There are many solutions for *nix platforms that I'm not interested in. I'm using ActivePerl 5.10.
推荐答案
这个线程上 Perlmonks 建议你可以做一个套接字非阻塞在Windows上用Perl这样的:
This thread on Perlmonks suggests you can make a socket nonblocking on Windows in Perl this way:
ioctl($socket, 0x8004667e, 1);
更多细节及资源在该线程
More details and resources in that thread
这篇关于Perl的 - 的Win32 - 如何做从其他处理的文件句柄的非阻塞读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!