コード例 #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
ファイル: TChannel.cs プロジェクト: wudiliujie/GameServer
        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
ファイル: TChannel.cs プロジェクト: wudiliujie/GameServer
        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();
        }