为什么从套接字读取时我的 Perl sysread 会阻塞? [英] Why does my Perl sysread block when reading from a socket?

查看:52
本文介绍了为什么从套接字读取时我的 Perl sysread 会阻塞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 AIX 5.3 上的 Perl 5.8.2 中执行 sysread.根据文档,sysread 应该在从文件句柄读取所有读取时给出 0.

I m doing a sysread in Perl 5.8.2 on AIX 5.3. As per the documentation, sysread is supposed to give 0 when it has read all read from filehandle.

在我的场景中,文件句柄是 STDIN 并指向一个套接字.所以我基本上是从套接字做一个 sysread .但是我从来没有从 sysread 得到 0 并且它只是阻塞,即使客户端发送了所有数据.

In my scenario, the filehandle is STDIN and points to a socket. So I m basically doing a sysread from a socket. But I never get 0 from sysread and it just blocks, even after client has sent all data.

知道哪里出了问题吗?

谢谢.

推荐答案

发送所有数据"是什么意思?sysread 在句柄遇到文件结束条件时返回零,而不是在现在没有更多可用数据时返回.对于套接字,当另一方关闭套接字以进行写入时,会发生 EOF 读取.(好吧,如果发生网络超时等错误,sysread 也会返回 undef,它在数字上等于 0.)

What do you mean "sent all data"? sysread returns zero when the handle encounters an end-of-file condition, not when there's no more data available right now. For a socket, EOF on read occurs when the other side has shutdown the socket for write. (Well, and sysread will also return undef, which is numerically equal to zero, if an error occurs such as a network timeout.)

这篇关于为什么从套接字读取时我的 Perl sysread 会阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆