M
Michi Henning
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
}
}
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
}
}