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