On Mon, 18 Nov 2013 15:17:07 GMT, Atila Neves wrote:

listenTCP and listenTCP_s take a delegate/function and runs it in its own fiber. Is there any way to pass this fiber to another thread?

What I want to do is divide the connections up between threads in a thread pool, each thread handling only its own fibers and corresponding sockets.

Is there a way to do that in vibe.d? Thanks in advance,

Atila

You can achieve that using TCPListenOptions.distribute:

void handleConnection(TCPConnection conn)
{
	// ...
}

void startup()
{
	enableWorkerThreads();
	listenTCP(1234, &handleConnection, TCPListenOptions.distribute);
}

This will listen in each of vibe.d's worker threads (equal to the number of CPU cores) on the same socket and let the OS decide which thread handles each incoming connection. This has the advantage of not requiring any inter-thread communication (such as sending the connection using message passing).