예제 #1
0
        public override AChannel GetChannel(long id)
        {
            TChannel channel = null;

            this.idChannels.TryGetValue(id, out channel);
            return(channel);
        }
예제 #2
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}");
                return;
            }
            TChannel channel = new TChannel(e.AcceptSocket, this);

            this.idChannels[channel.Id] = channel;

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

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

            this.AcceptAsync();
        }
예제 #3
0
        public override AChannel ConnectChannel(IPEndPoint ipEndPoint)
        {
            TChannel channel = new TChannel(ipEndPoint, this);

            this.idChannels[channel.Id] = channel;

            return(channel);
        }
예제 #4
0
        public override AChannel ConnectChannel(IPEndPoint ipEndPoint)
        {
            TcpClient tcpClient = new TcpClient();
            TChannel  channel   = new TChannel(tcpClient, ipEndPoint, this);

            this.idChannels[channel.Id] = channel;

            return(channel);
        }
예제 #5
0
        public override AChannel ConnectChannel(string host, int port)
        {
            TcpClient tcpClient = new TcpClient();
            TChannel  channel   = new TChannel(tcpClient, host, port, this);

            this.idChannels[channel.Id] = channel;

            return(channel);
        }
예제 #6
0
        public override AChannel ConnectChannel(string host, int port)
        {
            TSocket  newSocket = new TSocket(this.poller);
            TChannel channel   = new TChannel(newSocket, host, port, this);

            this.idChannels[channel.Id] = channel;

            return(channel);
        }
예제 #7
0
 public void 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();
 }
예제 #8
0
        public override async Task <AChannel> AcceptChannel()
        {
            if (this.acceptor == null)
            {
                throw new Exception("service construct must use host and port param");
            }
            TcpClient tcpClient = await this.acceptor.AcceptTcpClientAsync();

            TChannel channel = new TChannel(tcpClient, this);

            this.idChannels[channel.Id] = channel;
            return(channel);
        }
예제 #9
0
        public override void Dispose()
        {
            if (this.acceptor == null)
            {
                return;
            }

            foreach (long id in this.idChannels.Keys.ToArray())
            {
                TChannel channel = this.idChannels[id];
                channel.Dispose();
            }
            this.acceptor.Stop();
            this.acceptor = null;
        }
예제 #10
0
        public override async Task <AChannel> AcceptChannel()
        {
            if (this.acceptor == null)
            {
                throw new Exception("service construct must use host and port param");
            }
            TSocket socket = new TSocket(this.poller);

            await this.acceptor.AcceptAsync(socket);

            TChannel channel = new TChannel(socket, this);

            this.idChannels[channel.Id] = channel;
            return(channel);
        }