private MapEntry put(SelectionKeyImpl ski) { MapEntry mapEntry = new MapEntry(ski); Add(((SelChImpl)ski.channel()).getFDVal(), mapEntry); return(mapEntry); }
private MapEntry remove(SelectionKeyImpl ski) { int fd = ((SelChImpl)ski.channel()).getFDVal(); MapEntry x = get(fd); if ((x != null) && (x.ski.channel() == ski.channel())) { Remove(fd); return(x); } return(null); }
protected override void implRegister(SelectionKeyImpl ski) { lock (closeLock) { // if (pollWrapper == null) // throw new ClosedSelectorException(); growIfNeeded(); channelArray[totalChannels] = ski; ski.setIndex(totalChannels); // fdMap.put(ski); keys.Add(ski); // pollWrapper.addEntry(totalChannels, ski); totalChannels++; } }
public override SelectionKey register(AbstractSelectableChannel ch, Object attachment) { if (!(ch is SelChImpl)) { throw new IllegalSelectorException(); } SelectionKeyImpl k = new SelectionKeyImpl((SelChImpl)ch, this); k.attach(attachment); lock (publicKeys) { implRegister(k); } return(k); }
private void growIfNeeded() { if (channelArray.Length == totalChannels) { int newSize = totalChannels * 2; // Make a larger array SelectionKeyImpl[] temp = new SelectionKeyImpl[newSize]; Array.Copy(channelArray, 1, temp, 1, totalChannels - 1); channelArray = temp; // pollWrapper.grow(newSize); } if (totalChannels % MAX_SELECTABLE_FDS == 0) { // more threads needed // pollWrapper.addWakeupSocket(wakeupSourceFd, totalChannels); totalChannels++; // threadsCount++; } }
protected override void implDereg(SelectionKeyImpl ski) { int i = ski.getIndex(); if (i < 0) { throw new Exception(); } lock (closeLock) { if (i != totalChannels - 1) { // Copy end one over it SelectionKeyImpl endChannel = channelArray[totalChannels - 1]; channelArray[i] = endChannel; endChannel.setIndex(i); // pollWrapper.replaceEntry(pollWrapper, totalChannels - 1, pollWrapper, i); } ski.setIndex(-1); } channelArray[totalChannels - 1] = null; totalChannels--; if (totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) { totalChannels--; // threadsCount--; // The last thread has become redundant. } // fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys keys.Remove(ski); selectedKeys.Remove(ski); deregister(ski); SelectableChannel selch = ski.channel(); // if (!selch.isOpen() && !selch.isRegistered()) // ((SelChImpl)selch).kill(); }
protected abstract void implDereg(SelectionKeyImpl ski);
protected abstract void implRegister(SelectionKeyImpl ski);
public MapEntry(SelectionKeyImpl ski) { this.ski = ski; }
public void deRegister(SelectionKeyImpl ski) { implDereg(ski); }