On 12/13/2013 04:11 PM, Irving Montalvo wrote:
How do I pass a socket to concurrency?
send(tid, cli); // Socket cli
----------------------
receive (
(Socket cli) {
cli.send("1234567890");
}
)
-----
Help me :)
Unfortunately, some cast(shared) is needed at this time:
import std.stdio;
import std.socket;
import std.concurrency;
import core.thread;
struct Done
{}
void main()
{
shared(Socket)[ulong] clients;
clients[10000] =
cast(shared)new Socket(AddressFamily.UNIX, SocketType.STREAM);
auto tid = spawn(&server);
send(tid, clients[10000]);
send(tid, Done());
thread_joinAll();
}
void server()
{
bool done = false;
while (!done) {
receive(
(shared(Socket) client) {
writeln("received client");
},
(Done _) {
done = true;
}
);
}
}
Ali