示例#1
0
文件: TChannel.cs 项目: lisg2016/ET
        private void OnSendComplete(object o)
        {
            if (this.IsDisposed)
            {
                throw new Exception("TChannel已经被Dispose, 不能发送消息");
            }
            SocketAsyncEventArgs e             = (SocketAsyncEventArgs)o;
            UserTokenInfo        userTokenInfo = (UserTokenInfo)e.UserToken;

            if (userTokenInfo.InstanceId != this.InstanceId)
            {
                Log.Error($"session disposed!");
                return;
            }

            if (e.SocketError != SocketError.Success)
            {
                this.OnError((int)e.SocketError);
                return;
            }
            this.sendBuffer.FirstIndex += e.BytesTransferred;
            if (this.sendBuffer.FirstIndex == this.sendBuffer.ChunkSize)
            {
                this.sendBuffer.FirstIndex = 0;
                this.sendBuffer.RemoveFirst();
            }

            this.StartSend();
        }
示例#2
0
文件: TChannel.cs 项目: lisg2016/ET
        private void OnConnectComplete(object o)
        {
            if (this.IsDisposed)
            {
                throw new Exception("TChannel已经被Dispose, 不能发送消息");
            }
            SocketAsyncEventArgs e             = (SocketAsyncEventArgs)o;
            UserTokenInfo        userTokenInfo = (UserTokenInfo)e.UserToken;

            if (userTokenInfo.InstanceId != this.InstanceId)
            {
                Log.Error($"session disposed!");
                return;
            }

            if (e.SocketError != SocketError.Success)
            {
                this.OnError((int)e.SocketError);
                return;
            }

            e.RemoteEndPoint = null;
            this.isConnected = true;

            this.Start();
        }
示例#3
0
        private void OnAcceptComplete(object sender, SocketAsyncEventArgs o)
        {
            SocketAsyncEventArgs e             = o;
            UserTokenInfo        userTokenInfo = (UserTokenInfo)e.UserToken;

            if (userTokenInfo.InstanceId != this.InstanceId)
            {
                return;
            }

            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 (userTokenInfo.InstanceId != this.InstanceId)
            {
                return;
            }

            this.AcceptAsync();
        }
示例#4
0
文件: TChannel.cs 项目: lisg2016/ET
        private void OnRecvComplete(object o)
        {
            if (this.IsDisposed)
            {
                throw new Exception("TChannel已经被Dispose, 不能发送消息");
            }
            SocketAsyncEventArgs e             = (SocketAsyncEventArgs)o;
            UserTokenInfo        userTokenInfo = (UserTokenInfo)e.UserToken;

            if (userTokenInfo.InstanceId != this.InstanceId)
            {
                Log.Error($"session disposed!");
                return;
            }

            if (e.SocketError != SocketError.Success)
            {
                this.OnError((int)e.SocketError);
                return;
            }

            if (e.BytesTransferred == 0)
            {
                this.OnError((int)e.SocketError);
                return;
            }

            this.recvBuffer.LastIndex += e.BytesTransferred;
            if (this.recvBuffer.LastIndex == this.recvBuffer.ChunkSize)
            {
                this.recvBuffer.AddLast();
                this.recvBuffer.LastIndex = 0;
            }

            // 收到消息回调
            while (true)
            {
                if (!this.parser.Parse())
                {
                    break;
                }

                Packet packet = this.parser.GetPacket();
                try
                {
                    this.OnRead(packet);
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                }
            }

            if (userTokenInfo.InstanceId != this.InstanceId)
            {
                return;
            }
            this.StartRecv();
        }
示例#5
0
        private void OnConnectComplete(object o)
        {
            SocketAsyncEventArgs e             = (SocketAsyncEventArgs)o;
            UserTokenInfo        userTokenInfo = (UserTokenInfo)e.UserToken;

            if (userTokenInfo.InstanceId != this.InstanceId)
            {
                return;
            }

            if (e.SocketError != SocketError.Success)
            {
                Log.Debug("err:%v" + e.SocketError);
                this.OnError((int)e.SocketError);
                return;
            }
            this.isConnected = true;

            this.StartSend();
            this.StartRecv();
        }
示例#6
0
        private void OnConnectComplete(object o)
        {
            SocketAsyncEventArgs e             = (SocketAsyncEventArgs)o;
            UserTokenInfo        userTokenInfo = (UserTokenInfo)e.UserToken;

            if (userTokenInfo.InstanceId != this.InstanceId)
            {
                return;
            }

            if (e.SocketError != SocketError.Success)
            {
                this.OnError((int)e.SocketError);
                return;
            }

            e.RemoteEndPoint = null;
            this.isConnected = true;

            this.Start();
        }
示例#7
0
        private void OnSendComplete(object o)
        {
            SocketAsyncEventArgs e             = (SocketAsyncEventArgs)o;
            UserTokenInfo        userTokenInfo = (UserTokenInfo)e.UserToken;

            if (userTokenInfo.InstanceId != this.InstanceId)
            {
                return;
            }

            if (e.SocketError != SocketError.Success)
            {
                this.OnError((int)e.SocketError);
                return;
            }
            this.sendBuffer.FirstIndex += e.BytesTransferred;
            if (this.sendBuffer.FirstIndex == this.sendBuffer.ChunkSize)
            {
                this.sendBuffer.FirstIndex = 0;
                this.sendBuffer.RemoveFirst();
            }

            this.StartSend();
        }