View previous topic :: View next topic |
Author |
Message |
jcomellas
Joined: 30 Jan 2006 Posts: 22 Location: Buenos Aires, Argentina
|
Posted: Tue Apr 18, 2006 8:12 pm Post subject: Reactor (event demultiplexer) |
|
|
I'm going to start working on a Reactor interface for Mango. Here's the tentative interface I have so far. I'd like to receive some feedback from anyone who's interested in it.
Code: |
/**
* Reactor (i.e. event demultiplexer) interface.
*/
interface IReactor
{
public
{
enum Event: uint
{
Read = 0x01,
Write = 0x04,
Exception = 0x08,
ReadWrite = Read | Write,
ReadWriteException = Read | Write | Exception,
Accept = 0x11,
Connect = 0x14,
Timeout = 0x21,
QoS = 0x22,
Signal = 0x24,
All = 0xff
}
typedef int Timer;
abstract void open(uint size);
abstract void close();
abstract void run();
abstract void run(Interval interval);
abstract void stop();
// I/O related methods
abstract void register(bool delegate(IConduit conduit, uint event) eventHandler,
IConduit conduit, uint events);
abstract void reregister(bool delegate(IConduit conduit, uint event) eventHandler,
IConduit conduit, uint events);
abstract void unregister(IConduit conduit);
// Timer related methods
abstract Timer register(bool delegate(Timer timer, uint event) timerHandler,
Interval delay, Interval timeout);
abstract void reregister(bool delegate(Timer timer, uint event) timerHandler,
Timer timer, Interval timeout);
abstract void unregister(Timer timer);
version (Posix)
{
// Signal related methods
abstract void register(bool delegate(int signo) signalHandler, int signo);
abstract void reregister(bool delegate(int signo) signalHandler, int signo);
abstract void unregister(int signo);
}
}
protected void notify(IConduit conduit, uint events);
protected void notify(Timer timer);
protected void notify(int signo);
}
|
Last edited by jcomellas on Tue Apr 18, 2006 8:22 pm; edited 1 time in total |
|
Back to top |
|
|
jcomellas
Joined: 30 Jan 2006 Posts: 22 Location: Buenos Aires, Argentina
|
Posted: Tue Apr 18, 2006 8:16 pm Post subject: Re: Reactor (event demultiplexer) |
|
|
BTW, normally Reactors are written so that events are handled by an EventHandler class. I've written this interface using just delegates for the event handlers, because this should make the Reactor much simpler to use. I'm still not completely sure if this is the correct approach. Any comments will be appreciated. |
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Tue Apr 18, 2006 10:06 pm Post subject: |
|
|
--just a quick reply before I head off to make some dinner.
The interface looks good. It handles just about everything I'd want to do, and it does so quite cleanly. As for using delegates instead of classes, that seems appropriate since class methods are delegates anyway--there's simply no reason to use proxy objects in D as I'd do in C++. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|