Tk fileevent 不适用于 Windows 上的套接字
最近我一直在使用 perl 和 Tk 在 Windows 上开发 GUI 应用程序。在这个环境中有很多烦人的事情在 Linux 中工作得很好。最烦人的事情之一是 fileevent 似乎不起作用。我有一个 Net::Telnet 会话,我将其传递给 fileevent,在 Linux 中它工作正常,在 Windows 中,回调永远不会被调用。我发现了几个关于 perl 僧侣讨论解决方法的帖子,我认为涉及轮询,这是不希望的。首先,有谁知道为什么这不起作用? Select 在 Windows 中支持套接字,我怀疑内部有使用 select 吗?
Lately I have been developing GUI applications on windows with perl and Tk. There are many annoying things in this environment that work fine in Linux. One of the most annoying is that fileevent does not appear to work. I have a Net::Telnet session that I pass to fileevent, in Linux it works fine, in windows, the callback never gets called. I have found several posts on perl monks discussing workarounds, I think involving polling, this is not desired. First off, does anyone know why this does not work? Select supports sockets in windows, I would suspect there are using select internally no?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Windows 上的批评是很难实现非阻塞套接字。
在 Unix 中,您可以调用
$socket->blocking(0)
,这就是您所要做的一切,以确保您的套接字读取在没有输入可读取时不会阻塞。在 Windows 中,这不起作用,您需要在阅读之前轮询它们以确保其中有内容。除了轮询之外,我见过的另一个解决方法是在套接字句柄上调用 ioctl($socket,0x8004667e,1),其中 0x8004667e 是一个神奇的数字,用于在 Windows 套接字上启用非阻塞行为。我对此取得了不同程度的成功,并且不知道将其应用到 Net::Telnet 套接字可能会产生什么意想不到的后果。
The rap on Windows is that it's hard to implement non-blocking sockets.
In Unix you can invoke
$socket->blocking(0)
and that's all you have to do to make sure your socket reads won't block when there's no input to be read from them. In Windows, that doesn't work and you need to poll them to be sure there's something there before you read.In addition to polling, the other workaround I've seen is to call
ioctl($socket,0x8004667e,1)
on your socket handle, where 0x8004667e is a magic number to enable non-blocking behavior on Windows sockets. I've had mixed success with this and don't know what the unintended consequences might be applying it to aNet::Telnet
socket.