www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.socket Socket.select failing on consecutive calls with listening

reply cc <cc nevernet.com> writes:
	Socket server = new TcpSocket();
	server.setOption(SocketOptionLevel.SOCKET, 
SocketOption.REUSEADDR, true);
	server.bind(new InternetAddress(8000));
	server.listen(8);

	auto set = new SocketSet();
	set.add(server);

	auto sel = Socket.select(set, null, null, msecs(0));
	Socket.select(set, null, null, msecs(0));

(Simplified from loop) On the second select call, fails with:

std.socket.SocketOSException std\socket.d(3439): Socket select 
error: An invalid argument was supplied.


The ultimate goal is non-blocking accept calls.  I tried skipping 
the select() calls entirely and just setting  server.blocking = 
false;  and  auto client = server.accept();  every loop, but this 
resulted in accept() returning a non-null Socket object even when 
no client was connecting, and did not throw an exception to check 
for wouldHaveBlocked.  When I added the select statement to check 
for pending connections, the first iteration returns 0 
successfully, but the second iteration of the loop failed with 
the above message.

(DMD32 D Compiler v2.071.1 running on Windows 7 x64)
Jul 31 2016
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Sunday, 31 July 2016 at 08:00:02 UTC, cc wrote:
socket sets usually updated after call to `select()`. you have to 
recreate the sets before each call.
Jul 31 2016
parent cc <cc nevernet.com> writes:
On Sunday, 31 July 2016 at 08:29:10 UTC, ketmar wrote:
 On Sunday, 31 July 2016 at 08:00:02 UTC, cc wrote:
 socket sets usually updated after call to `select()`. you have 
 to recreate the sets before each call.
Ah that works, thanks.
Jul 31 2016