我在套接字上使用阻塞的Select()调用 超时值为-1。我希望这个电话会无限期阻止,但事实并非如此。当我使用Poll()时, a超时-1工作正常并且无限期地阻塞。 净效果是我不能写更多选择 比一个文件描述符,如果我想阻止。 (使用 超时值> = 0,Select()和Poll()都可正常工作。) 要重现,请运行以下代码并telnet从另一个窗口到12345的127.0.0.1 。 Select()版本 立即返回,即使它不应该,而 Poll()版本正确阻止并返回一次 你点击了telnet窗口中的任意一个键。 干杯, Michi。 #定义SHOW_BUG 使用System; 使用System.Collections; 使用System.Net; 使用System.Net.Sockets; 类服务器 { static void Main(string [] args) { Socket s = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); s.Bind(new IPEndPoint(IPAddress) .Parse(" 127.0.0.1"),12345)); s.Listen(1); Socket c = s.Accept(); #if SHOW_BUG ArrayList readList = new ArrayList(); readList.Add(c); Socket。选择(readList,null,null,-1); Console.WriteLine(" Select return,可读描述符数量= + readList.Count); #else bool rc = c.Poll(-1,SelectMode.SelectRead); Console.WriteLine (Poll返回+ rc); #endif } }
解决方案Michi Henning< mi *** @ zeroc>写道:我正在使用阻塞的Select()调用套接字,其超时值为-1。我希望这个电话无限期阻止,但事实并非如此。当我使用Poll()代替时, -1的超时工作正常并且无限期地阻塞。
为什么你会期望它无限期地阻塞?我不能在 中看到任何文件来表明它应该 - 而民意调查 文件*确实*说负值会导致潜在的/> 无限期等待。 - Jon Skeet - < sk *** @ pobox> www.pobox/~skeet 如果回复该组,请不要给我发邮件
" Jon Skeet [C#MVP]" < SK *** @ pobox>在消息中写道 新闻:MP ************************ @ msnews.microsoft.c om ... Michi Henning< mi *** @ zeroc>写道:我正在使用阻塞的Select()调用套接字,其超时值为-1。我希望这个电话无限期阻止,但事实并非如此。当我使用Poll()代替时, -1的超时工作正常并无限期地阻塞。
为什么你会期望它无限期地阻塞?我无法在文档中看到任何暗示它应该的内容 - 而民意调查文档*确实*说负值会导致潜在的无限期等待。 对,这正是文档所说的。但本机select()(在SDK中) 在使用否定超时调用时无限期阻塞。而且,如果文档中说的是真正的预期,那么根据一次就多个套接字进行阻塞选择根本就没有办法 。这显然是一个错误 - 如果我有多个数据源我想要监控 的活动,除非我这样做,否则我不能这样做忙碌的等待。 如果Poll()无限期地阻止负超时,那么Select() (这正是我''时发生的事情使用SDK代替 .NET frameowork)。 干杯, Michi。 - Michi Henning电话:+61 4 1118-2700 ZeroC,Inc。 www.zeroc
Michi Henning < MI *** @ triodia>在新闻中写道:OZeRL
Hi, I''m using a blocking Select() call on a socket with a timeout value of -1. I''d expect the call to block indefinitely, but it doesn''t. When I use Poll() instead, a timeout of -1 works fine and blocks indefinitely. The net effect is that I cannot write a select on more than one file descripter if I want to block. (With timeout values >= 0, both Select() and Poll() work fine.) To reproduce, run the code below and telnet to 127.0.0.1 at port 12345 from another window. The Select() version returns immediately even though it shouldn''t, whereas the Poll() version correctly blocks and returns once you hit any key in the telnet window. Cheers, Michi. #define SHOW_BUG using System; using System.Collections; using System.Net; using System.Net.Sockets; class Server { static void Main(string[] args) { Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 12345)); s.Listen(1); Socket c = s.Accept(); #if SHOW_BUG ArrayList readList = new ArrayList(); readList.Add(c); Socket.Select(readList, null, null, -1); Console.WriteLine("Select returned, number of readable descriptors = " + readList.Count); #else bool rc = c.Poll(-1, SelectMode.SelectRead); Console.WriteLine("Poll returned " + rc); #endif } }
解决方案 Michi Henning <mi***@zeroc> wrote: I''m using a blocking Select() call on a socket with a timeout value of -1. I''d expect the call to block indefinitely, but it doesn''t. When I use Poll() instead, a timeout of -1 works fine and blocks indefinitely.Why would you expect it to block indefinitely? I can''t see anything in the documentation to suggest that it should - whereas the Poll documentation *does* say that a negative value will cause a potentially indefinite wait. -- Jon Skeet - <sk***@pobox> www.pobox/~skeet If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox> wrote in message news:MP************************@msnews.microsoft.c om... Michi Henning <mi***@zeroc> wrote: I''m using a blocking Select() call on a socket with a timeout value of -1. I''d expect the call to block indefinitely, but it doesn''t. When I use Poll() instead, a timeout of -1 works fine and blocks indefinitely.Why would you expect it to block indefinitely? I can''t see anything in the documentation to suggest that it should - whereas the Poll documentation *does* say that a negative value will cause a potentially indefinite wait.
Right, that''s exactly what the doc says. But native select() (in the SDK) blocks indefinitely when called with a negative timeout. And, if what the documentation says is really as intended, there is simply no way to do a blocking select on more than a single socket at a time. That''s clearly a bug -- if I have multiple sources of data that I want to monitor for activity, I can''t do that unless I do a busy wait. If Poll() blocks indefinitely with a negative timeout, so should Select() (which is exactly what happens when I''m using the SDK instead of the .NET frameowork). Cheers, Michi. -- Michi Henning Ph: +61 4 1118-2700 ZeroC, Inc. www.zeroc
"Michi Henning" <mi***@triodia> wrote in news:OZeRL更多推荐
阻止Select()不起作用
发布评论