On Tuesday, 20 November 2012 at 15:21:12 UTC, H. S. Teoh wrote:
It should work at the file descriptor level, perhaps even
combining with signal handling (using the self-pipe trick)

I was thinking we'd send pointers and a type hash through a pipe. It'd keep the read/write very simple.

Now, the event data must be defined to be transient, unless specifically told otherwise (e.g. immutable types), because then we can reuse the data structures to avoid allocations.

But take a gander at this:
http://arsdnet.net/dcode/typehash.d

We can take any type tuple, do a mangle of and get a unique
name for any combination of arguments. Then hash it, and we
have a nicely unique, fixed size message to send down the pipe.


One one end, we'll cast to a void* and send that along with the hash.

On the other side, only listener functions who's ParameterTypeTuple matches the typehash will receive a message. They can then cast the void* back to the argument type with confidence.



This lets us define custom messages as plain types:

struct MyMessage {
   string text;
}


event.listen((MyMessage m) { writeln("Received: ", m.text); }
event.send(MyMessage("hello!"));

event.loop(); // we should receive the message and call the above func



If there's no listener that matches the hash, we ignore the message. Now there'd be some care needed to not send pointers to stack data down the pipe, as that could be destroyed, but eh.

Some details gotta be worked out but I really like the idea of using type names like this.

Reply via email to