예제 #1
0
 internal override Socket registerForSelection(Selector selector)
 {
     selector.Add(channel, Selector.Direction.READ);
     return channel;
 }
예제 #2
0
        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;
        }
예제 #3
0
 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;
     }
 }
예제 #4
0
 private void openSelector()
 {
     try
     {
         lock (this)
         {
             selector = new Selector();
             // Selector.open();
             if (stopRequest)
             {
                 selector.Wakeup();
             }
         }
     }
     catch (SocketException)
     {
     // ignore
     }
 }
예제 #5
0
 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
     }
 }
예제 #6
0
 // to be defined by concrete listener
 internal abstract Socket registerForSelection(Selector selector);