Exemplo n.º 1
0
		public static Record Receive (Socket socket, Buffers buffers)
		{
			if (socket == null)
				throw new ArgumentNullException ("socket");

			CompatArraySegment<byte> header_buffer = buffers.EnforceHeaderLength (HEADER_SIZE);

			// Read the 8 byte record header.
			ReceiveAll (socket, header_buffer, HEADER_SIZE);

			// Read the values from the data.
			var version         = header_buffer [0];
			var type            = (RecordType) header_buffer [1];
			var requestID       = ReadUInt16 (header_buffer, 2);
			var bodyLength      = ReadUInt16 (header_buffer, 4);
			byte padding_length = header_buffer [6];

			CompatArraySegment<byte> body_buffer  = buffers.EnforceBodyLength (bodyLength);

			// Read the record data, and throw an exception if the
			// complete data cannot be read.
			if (bodyLength > 0)
				ReceiveAll (socket, body_buffer, bodyLength);

			CompatArraySegment<byte> padding_buffer = buffers.EnforcePaddingLength (padding_length);

			if(padding_length > 0)
				ReceiveAll(socket, padding_buffer, padding_length);

			Logger.Write (LogLevel.Debug, Strings.Record_Received, type, requestID, bodyLength);

			return new Record (version, type, requestID, bodyLength, buffers);
		}
Exemplo n.º 2
0
		public Record (Socket socket, Buffers receive_buffer) : this()
		{
			if (socket == null)
				throw new ArgumentNullException ("socket");

			CompatArraySegment<byte> header_buffer = receive_buffer.EnforceHeaderLength (HeaderSize);

			// Read the 8 byte record header.
			NRecord.ReceiveAll (socket, header_buffer, HeaderSize);

			// Read the values from the data.
			version        = header_buffer [0];
			type           = (RecordType) header_buffer [1];
			request_id     = NRecord.ReadUInt16 (header_buffer, 2);
			BodyLength     = NRecord.ReadUInt16 (header_buffer, 4);
			byte padding_length = header_buffer [6];

			CompatArraySegment<byte> body_buffer  = receive_buffer.EnforceBodyLength (BodyLength);

			// Read the record data, and throw an exception if the
			// complete data cannot be read.
			if (BodyLength > 0)
				NRecord.ReceiveAll (socket, body_buffer, BodyLength);

			CompatArraySegment<byte> padding_buffer = receive_buffer.EnforcePaddingLength (padding_length);

			if(padding_length > 0)
				NRecord.ReceiveAll(socket, padding_buffer, padding_length);

			buffers = receive_buffer;

			Logger.Write (LogLevel.Debug, Strings.Record_Received, Type, RequestID, BodyLength);
		}
Exemplo n.º 3
0
 public Record(byte version, RecordType type, ushort requestID, int bodyLength, Buffers buffers) : this()
 {
     Version    = version;
     Type       = type;
     RequestID  = requestID;
     BodyLength = (ushort)bodyLength;
     Content    = buffers;
 }
Exemplo n.º 4
0
		public Record (byte version, RecordType type, ushort requestID, int bodyLength, Buffers buffers) : this()
		{
			Version = version;
			Type = type;
			RequestID  = requestID;
			BodyLength = (ushort) bodyLength;
			Content = buffers;
		}
Exemplo n.º 5
0
		public Connection (Socket socket, Server server)
		{
			if (socket == null)
				throw new ArgumentNullException ("socket");
			if (server == null)
				throw new ArgumentNullException ("server");
			
			this.socket = socket;
			this.server = server;

			receive_buffers = new Buffers(server.BigBufferManager, server.SmallBufferManager);
			send_buffers = new Buffers (server.BigBufferManager, server.SmallBufferManager);
		}
Exemplo n.º 6
0
        public static Record Receive(Socket socket, Buffers buffers)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            CompatArraySegment <byte> header_buffer = buffers.EnforceHeaderLength(HEADER_SIZE);

            // Read the 8 byte record header.
            ReceiveAll(socket, header_buffer, HEADER_SIZE);

            // Read the values from the data.
            var  version        = header_buffer [0];
            var  type           = (RecordType)header_buffer [1];
            var  requestID      = ReadUInt16(header_buffer, 2);
            var  bodyLength     = ReadUInt16(header_buffer, 4);
            byte padding_length = header_buffer [6];

            CompatArraySegment <byte> body_buffer = buffers.EnforceBodyLength(bodyLength);

            // Read the record data, and throw an exception if the
            // complete data cannot be read.
            if (bodyLength > 0)
            {
                ReceiveAll(socket, body_buffer, bodyLength);
            }

            CompatArraySegment <byte> padding_buffer = buffers.EnforcePaddingLength(padding_length);

            if (padding_length > 0)
            {
                ReceiveAll(socket, padding_buffer, padding_length);
            }

            Logger.Write(LogLevel.Debug, Strings.Record_Received, type, requestID, bodyLength);

            return(new Record(version, type, requestID, bodyLength, buffers));
        }
Exemplo n.º 7
0
		public Record (byte version, RecordType type, ushort requestID,
		               byte [] bodyData, int bodyIndex, int bodyLength) : this()
		{
			if (bodyData == null)
				throw new ArgumentNullException ("bodyData");
			
			if (bodyIndex < 0 || bodyIndex > bodyData.Length)
				throw new ArgumentOutOfRangeException (
					"bodyIndex");
			
			if (bodyLength < 0)
				bodyLength = bodyData.Length - bodyIndex;
			
			if (bodyLength > 0xFFFF)
				throw new ArgumentException (
					Strings.Record_DataTooBig,
					"bodyLength");


			this.version = version;
			this.type = type;
			request_id  = requestID;
			buffers = new Buffers (bodyData, bodyIndex, bodyLength);
			BodyLength = (ushort) bodyLength;
		}
Exemplo n.º 8
0
		public Record (byte version, RecordType type, ushort requestID,
		               Buffers buffers, int bodyLength) : this()
		{
			this.version = version;
			this.type = type;
			request_id  = requestID;
			this.buffers = buffers;
			BodyLength = (ushort) bodyLength;
		}