コード例 #1
0
 public void RegisterListener(TimeSpan timeout, DemuxSocketListener listener)
 {
     if (listener.Type.Length > 100)
     {
         throw new ArgumentOutOfRangeException("listener", SRClient.ListenerLengthArgumentOutOfRange);
     }
     lock (this.listenerTable)
     {
         this.listenerTable.Add(listener.Type, listener);
         if (this.listenerTable.Count == 1)
         {
             this.innerListener = this.innerElement.CreateListener(this.bufferSize, this.uri);
             this.innerListener.Open(timeout);
             this.StartAccepting();
         }
     }
 }
コード例 #2
0
        private void ProcessConnection(IConnection connection)
        {
            bool flag = false;

            try
            {
                byte[] numArray = new byte[4];
                if (connection.Read(numArray, 0, 4, TimeSpan.FromSeconds(1)) == 4)
                {
                    int num = BitConverter.ToInt32(numArray, 0);
                    if (num <= 100)
                    {
                        byte[] numArray1 = new byte[num];
                        if (connection.Read(numArray1, 0, num, TimeSpan.FromSeconds(1)) == num)
                        {
                            string str = Encoding.UTF8.GetString(numArray1);
                            DemuxSocketListener demuxSocketListener = null;
                            lock (this.listenerTable)
                            {
                                if (!this.listenerTable.TryGetValue(str, out demuxSocketListener))
                                {
                                    return;
                                }
                            }
                            demuxSocketListener.EnqueueConnection(connection, new Action(this.OnConnectionDequeued));
                            flag = true;
                        }
                    }
                }
            }
            finally
            {
                if (!flag)
                {
                    connection.Close(TimeSpan.FromSeconds(1));
                }
            }
        }
コード例 #3
0
        public void UnregisterListener(TimeSpan timeout, DemuxSocketListener listener)
        {
            DemuxSocketListener demuxSocketListener;

            lock (this.listenerTable)
            {
                if (this.listenerTable.TryGetValue(listener.Type, out demuxSocketListener) && demuxSocketListener == listener)
                {
                    this.listenerTable.Remove(listener.Type);
                    if (this.listenerTable.Count == 0)
                    {
                        if (timeout != TimeSpan.Zero)
                        {
                            this.innerListener.Close(timeout);
                        }
                        else
                        {
                            this.innerListener.Abort();
                        }
                        this.innerListener = null;
                    }
                }
            }
        }