public void removeKey(SelectionKey k) { lock (keyLock) { for (int i = 0; i < keys.Length; i++) { if (keys[i] == k) { keys[i] = null; keyCount--; } } // ((AbstractSelectionKey)k).invalidate(); } }
public override SelectionKey register(Selector sel, Object att) { lock (regLock) { SelectionKey k = findKey(sel); if (k != null) { k.attach(att); } if (k == null) { // New registration lock (keyLock) { // sabal continue k = ((AbstractSelector)sel).register(this, att); addKey(k); } } return(k); } }
private void addKey(SelectionKey k) { Debug.Assert(Monitor.TryEnter(keyLock)); int i = 0; if ((keys != null) && (keyCount < keys.Length)) { // Find empty element of key array for (i = 0; i < keys.Length; i++) { if (keys[i] == null) { break; } } } else if (keys == null) { keys = new SelectionKey[3]; } else { // Grow key array int n = keys.Length * 2; SelectionKey[] ks = new SelectionKey[n]; for (i = 0; i < keys.Length; i++) { ks[i] = keys[i]; } keys = ks; i = keyCount; } keys[i] = k; keyCount++; }