internal virtual SelectionKeys registerForSelection(Selector selector, bool allowInput, bool allowOutput, bool useBlockingOnly) { Selector.Direction operations = Selector.Direction.NONE; if (allowInput) { operations |= Selector.Direction.READ; } // do not register for output if there is nothing to write bool hasSomeOutgoingFrames = channelWriter.hasSomeOutgoingFrames(); if (allowOutput && hasSomeOutgoingFrames) { operations |= Selector.Direction.WRITE; } Socket key = null; if (operations != 0) { try { key = connection.register(selector, operations, useBlockingOnly); } //TODO replace with proper exception catch //catch (ClosedChannelException ex) { // ignore, will never happen } } SelectionKeys keys = new SelectionKeys(); keys.key = key; keys.blockingChannelReadyForReading = ((operations & Selector.Direction.READ) != 0) && connection.readingQueue != null && connection.readingQueue.HasDataOrEOF(); keys.blockingChannelReadyForWriting = (operations & Selector.Direction.WRITE) != 0; return(keys); }