Example #1
0
        public int WriteToFile(G2Packet packet, Stream stream)
        {
            byte[] data = packet.Encode(this);

            stream.Write(data, 0, data.Length);

            return(data.Length);
        }
Example #2
0
        public int SendPacket(G2Packet packet)
        {
            Debug.Assert(Thread.CurrentThread.ManagedThreadId == XRay.CoreThread.ManagedThreadId, "Send packet called not on core thread");

            if (State != TcpState.Connected)
            {
                return(0);
            }

            try
            {
                byte[]         encoded  = packet.Encode(Protocol);
                PacketLogEntry logEntry = new PacketLogEntry(DateTime.Now, DirectionType.Out, ToString(), encoded);
                LogPacket(logEntry);

                // fill up final buffer, keep encrypt buffer clear
                if (BUFF_SIZE - SendBuffSize < encoded.Length + 128)
                {
                    throw new Exception("SendBuff Full");
                }

                // encrypt
                encoded.CopyTo(SendBuffer, SendBuffSize);
                SendBuffSize += encoded.Length;

                OnlyFillerInSendBuffer = false;

                TrySend();

                // record bandwidth
                return(encoded.Length);
            }
            catch (Exception ex)
            {
                Log("SendPacket", ex.Message);
            }

            return(0);
        }
Example #3
0
 public int WritePacket(G2Packet packet)
 {
     byte[] data = packet.Encode(Protocol);
     ParentStream.Write(data, 0, data.Length);
     return(data.Length);
 }
Example #4
0
 public int WritePacket(G2Packet packet)
 {
     byte[] data = packet.Encode(Protocol);
     ParentStream.Write(data, 0, data.Length);
     return data.Length;
 }
Example #5
0
        public int WriteToFile(G2Packet packet, Stream stream)
        {
            byte[] data = packet.Encode(this);

            stream.Write(data, 0, data.Length);

            return data.Length;
        }
Example #6
0
        public int SendPacket(G2Packet packet)
        {
            Debug.Assert(Thread.CurrentThread.ManagedThreadId == XRay.CoreThread.ManagedThreadId, "Send packet called not on core thread");

            if (State != TcpState.Connected)
                return 0;

            try
            {
                byte[] encoded = packet.Encode(Protocol);
                PacketLogEntry logEntry = new PacketLogEntry(DateTime.Now, DirectionType.Out, ToString(), encoded);
                LogPacket(logEntry);

                // fill up final buffer, keep encrypt buffer clear
                if (BUFF_SIZE - SendBuffSize < encoded.Length + 128)
                    throw new Exception("SendBuff Full");

                // encrypt
                encoded.CopyTo(SendBuffer, SendBuffSize);
                SendBuffSize += encoded.Length;

                OnlyFillerInSendBuffer = false;

                TrySend();

                // record bandwidth
                return encoded.Length;
            }
            catch (Exception ex)
            {
                Log("SendPacket", ex.Message);
            }

            return 0;
        }