Ejemplo n.º 1
0
 public void Enqueue(BSPacket p)
 {
     if (mSendList != null && p != null)
     {
         mSendList.Enqueue(p);
     }
 }
Ejemplo n.º 2
0
        private void ReceiveData(IAsyncResult result)
        {
            if (!Connected)
            {
                return;
            }

            int dataRead;

            try
            {
                dataRead = mClient.Client.EndReceive(result);
            }
            catch
            {
                Disconnecting = true;
                return;
            }

            byte[] rawBytes = result.AsyncState as byte[];
            byte[] temp     = mRawData;
            mRawData = new byte[dataRead + temp.Length];
            Buffer.BlockCopy(temp, 0, mRawData, 0, temp.Length);
            Buffer.BlockCopy(rawBytes, 0, mRawData, temp.Length, dataRead);

            BSPacket p;

            while ((p = BSPacket.ReceivePacket(mRawData, out mRawData)) != null)
            {
                mReceiveList.Enqueue(p);
            }

            BeginReceive();
        }
Ejemplo n.º 3
0
        public void Process()
        {
            if (mClient == null || !mClient.Connected)
            {
                // Socket Disconnected
                return;
            }

            while (!mReceiveList.IsEmpty && !Disconnecting)
            {
                BSPacket p;
                if (!mReceiveList.TryDequeue(out p))
                {
                    continue;
                }
                TimeoutTime = Core.Time + Settings.ConnectionTimeout;
                ProcessPacket(p);
            }

            while (mRetryList.Count > 0)
            {
                mReceiveList.Enqueue(mRetryList.Dequeue());
            }

            if (Core.Time > TimeoutTime)
            {
                // Timeout Disconnected
                return;
            }

            if (mSendList == null || mSendList.Count <= 0)
            {
                return;
            }

            List <byte> data = new List <byte>();

            while (mSendList.Count > 0)
            {
                BSPacket p = mSendList.Dequeue();
                data.AddRange(p.GetPacketBytes());
            }

            BeginSend(data);
        }
Ejemplo n.º 4
0
        private void ProcessPacket(BSPacket p)
        {
            if (p == null || Disconnecting)
            {
                return;
            }

            switch (p.Index)
            {
            case (short)R.ReceivePacketIds.KeepAlive:
                KeepAlive((R.KeepAlive)p);
                break;

            case (short)R.ReceivePacketIds.ClientVersion:
                ClientVersion((R.ClientVersion)p);
                break;
            }
        }