Destructor
Alias for the select() method as we're not reimplementing it in this class.
Class used to hold the list of Conduits that have received events.
Close the selector, releasing the file descriptor that had been created in the previous 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.
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.
Open the epoll selector, makes a call to epoll_create()
Associate a conduit to the selector and track specific I/O events. If a conduit is already associated, changes the events and attachment.
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.
Remove a conduit from the selector.
Default maximum number of events that will be received per invocation to select().
Default number of SelectionKey's that will be handled by the EpollSelector.
Restart interrupted system calls when blocking inside a call to select.
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.
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.
Deprecated, use register instead
Remove a conduit from the selector.
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.
Return the selection key resulting from the registration of a conduit to the selector.
Return the number of keys resulting from the registration of a conduit to the selector.
* Cast the time duration to a C timeval struct.
Check the 'errno' global variable from the C standard library and throw an exception with the description of the error.
1 import tango.io.selector.EpollSelector; 2 import tango.net.device.Socket; 3 import tango.io.Stdout; 4 5 SocketConduit conduit1; 6 SocketConduit conduit2; 7 EpollSelector selector = new EpollSelector(); 8 MyClass object1 = new MyClass(); 9 MyClass object2 = new MyClass(); 10 uint eventCount; 11 12 // Initialize the selector assuming that it will deal with 10 conduits and 13 // will receive 3 events per invocation to the select() method. 14 selector.open(10, 3); 15 16 selector.register(conduit1, Event.Read, object1); 17 selector.register(conduit2, 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"); 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, AbstractSelector
Selector that uses the Linux epoll* family of system calls.
This selector is the best option when dealing with large amounts of conduits under Linux. It will scale much better than any of the other options (PollSelector, SelectSelector). For small amounts of conduits (n < 20) the PollSelector will probably be more performant.