Check the 'errno' global variable from the C standard library and throw an exception with the description of the error.
Free any operating system resources that may have been allocated in the call to open().
Return the number of keys resulting from the registration of a conduit to the selector.
Return the selection key resulting from the registration of a conduit to the selector.
Initialize the selector.
Associate a conduit to the selector and track specific I/O events.
Deprecated, use register instead
Indicates whether interrupted system calls will be restarted when blocking inside a call to select.
Sets whether interrupted system calls will be restarted when blocking inside a call to select.
Wait for I/O events from the registered conduits for a specified amount of time.
Wait for I/O events from the registered conduits for a specified amount of time.
Wait for I/O events from the registered conduits for a specified amount of time.
Return the selection set resulting from the call to any of the select() methods.
* Cast the time duration to a C timeval struct.
Remove a conduit from the selector.
Restart interrupted system calls when blocking inside a call to select.
Initialize the selector.
Free any operating system resources that may have been allocated in the call to open().
Associate a conduit to the selector and track specific I/O events. If the conduit is already part of the selector, modify the events or atachment.
Deprecated, use register instead
Remove a conduit from the selector.
Wait indefinitely for I/O events from the registered conduits.
Wait for I/O events from the registered conduits for a specified amount of time.
Wait for I/O events from the registered conduits for a specified amount of time.
Return the selection set resulting from the call to any of the select() methods.
Return the selection key resulting from the registration of a conduit to the selector.
Iterate through the currently registered selection keys. Note that you should not erase or add any items from the selector while iterating, although you can register existing conduits again.
1 import tango.io.selector.model.ISelector; 2 import tango.net.device.Socket; 3 import tango.io.Stdout; 4 5 AbstractSelector selector; 6 SocketConduit conduit1; 7 SocketConduit conduit2; 8 MyClass object1; 9 MyClass object2; 10 uint eventCount; 11 12 // Initialize the selector assuming that it will deal with 2 conduits and 13 // will receive 2 events per invocation to the select() method. 14 selector.open(2, 2); 15 16 selector.register(conduit, Event.Read, object1); 17 selector.register(conduit, Event.Write, object2); 18 19 eventCount = selector.select(); 20 21 if (eventCount > 0) 22 { 23 char[16] buffer; 24 int count; 25 26 foreach (SelectionKey key, selector.selectedSet()) 27 { 28 if (key.isReadable()) 29 { 30 count = (cast(SocketConduit) key.conduit).read(buffer); 31 if (count != IConduit.Eof) 32 { 33 Stdout.format("Received '{0}' from peer\n", buffer[0..count]); 34 selector.register(key.conduit, Event.Write, key.attachment); 35 } 36 else 37 { 38 selector.unregister(key.conduit); 39 key.conduit.close(); 40 } 41 } 42 43 if (key.isWritable()) 44 { 45 count = (cast(SocketConduit) key.conduit).write("MESSAGE"); 46 if (count != IConduit.Eof) 47 { 48 Stdout("Sent 'MESSAGE' to peer\n"); 49 selector.register(key.conduit, Event.Read, key.attachment); 50 } 51 else 52 { 53 selector.unregister(key.conduit); 54 key.conduit.close(); 55 } 56 } 57 58 if (key.isError() || key.isHangup() || key.isInvalidHandle()) 59 { 60 selector.unregister(key.conduit); 61 key.conduit.close(); 62 } 63 } 64 } 65 66 selector.close();
ISelector
Base class for all selectors.
A selector is a multiplexor for I/O events associated to a Conduit. All selectors must implement this interface.
A selector needs to be initialized by calling the open() method to pass it the initial amount of conduits that it will handle and the maximum amount of events that will be returned per call to select(). In both cases, these values are only hints and may not even be used by the specific ISelector implementation you choose to use, so you cannot make any assumptions regarding what results from the call to select() (i.e. you may receive more or less events per call to select() than what was passed in the 'maxEvents' argument. The amount of conduits that the selector can manage will be incremented dynamically if necessary.
To add or modify conduit registrations in the selector, use the register() method. To remove conduit registrations from the selector, use the unregister() method.
To wait for events from the conduits you need to call any of the select() methods. The selector cannot be modified from another thread while blocking on a call to these methods.
Once the selector is no longer used you must call the close() method so that the selector can free any resources it may have allocated in the call to open().