Beispiel #1
0
            private MapEntry put(SelectionKeyImpl ski)
            {
                MapEntry mapEntry = new MapEntry(ski);

                Add(((SelChImpl)ski.channel()).getFDVal(), mapEntry);
                return(mapEntry);
            }
Beispiel #2
0
            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);
            }
Beispiel #3
0
        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++;
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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++;
            }
        }
Beispiel #6
0
        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();
        }
Beispiel #7
0
 protected abstract void implDereg(SelectionKeyImpl ski);
Beispiel #8
0
 protected abstract void implRegister(SelectionKeyImpl ski);
Beispiel #9
0
 public MapEntry(SelectionKeyImpl ski)
 {
     this.ski = ski;
 }
Beispiel #10
0
 public void deRegister(SelectionKeyImpl ski)
 {
     implDereg(ski);
 }