예제 #1
0
        private void OnAcceptComplete(object o)
        {
            if (this.acceptor == null)
            {
                return;
            }
            SocketAsyncEventArgs e = (SocketAsyncEventArgs)o;

            if (e.SocketError != SocketError.Success)
            {
                Log.Error($"accept error {e.SocketError}");
                this.AcceptAsync();
                return;
            }
            TChannel channel = new TChannel(e.AcceptSocket, this);

            this.idChannels[channel.Id] = channel;
            channel.Parent = this;

            try
            {
                this.OnAccept(channel);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }

            if (this.acceptor == null)
            {
                return;
            }

            this.AcceptAsync();
        }
예제 #2
0
        public override AChannel GetChannel(long id)
        {
            TChannel channel = null;

            this.idChannels.TryGetValue(id, out channel);
            return(channel);
        }
예제 #3
0
        public override AChannel ConnectChannel(IPEndPoint ipEndPoint)
        {
            TChannel channel = new TChannel(ipEndPoint, this);

            this.idChannels[channel.Id] = channel;
            channel.Parent = this;
            return(channel);
        }
예제 #4
0
        public override void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }

            base.Dispose();

            foreach (long id in this.idChannels.Keys.ToArray())
            {
                TChannel channel = this.idChannels[id];
                channel.Dispose();
            }
            this.acceptor?.Close();
            this.acceptor = null;
            this.innArgs.Dispose();
        }