internal override Socket registerForSelection(Selector selector) { selector.Add(channel, Selector.Direction.READ); return channel; }
internal virtual Socket registerForSelection(Selector selector, bool allowInput, bool allowOutput) { 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); } //TODO replace with proper exception catch //catch (ClosedChannelException ex) { // ignore, will never happen } } return key; }
internal virtual Socket register(Selector selector, Selector.Direction operations) { if (connectedChannel != null) { selector.Add(connectedChannel, operations); return connectedChannel; } else { selector.Add(datagramChannel, operations); return datagramChannel; } }
private void openSelector() { try { lock (this) { selector = new Selector(); // Selector.open(); if (stopRequest) { selector.Wakeup(); } } } catch (SocketException) { // ignore } }
private void closeSelector() { try { lock (this) { //foreach (Socket key in selector.keys()) //{ // key.cancel(); //} // selector.SelectNow(); selector.Close(); selector = null; } } catch (SocketException) { // ignore, will never happen } }
// to be defined by concrete listener internal abstract Socket registerForSelection(Selector selector);