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

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