Exemple #1
0
        /// <summary>Constructs an incoming request frame.</summary>
        /// <param name="protocol">The Ice protocol.</param>
        /// <param name="data">The frame data as an array segment.</param>
        /// <param name="maxSize">The maximum payload size, checked during decompression.</param>
        /// <param name="socketStream">The optional socket stream. The stream is non-null if there's still data to
        /// read on the stream after the reading the request frame.</param>
        internal IncomingRequestFrame(
            Protocol protocol,
            ArraySegment <byte> data,
            int maxSize,
            SocketStream?socketStream)
            : base(protocol, maxSize)
        {
            SocketStream = socketStream;

            var istr = new InputStream(data, Protocol.GetEncoding());

            if (Protocol == Protocol.Ice1)
            {
                var requestHeader = new Ice1RequestHeader(istr);
                Identity     = requestHeader.Identity;
                Facet        = Ice1Definitions.GetFacet(requestHeader.FacetPath);
                Location     = Array.Empty <string>();
                Operation    = requestHeader.Operation;
                IsIdempotent = requestHeader.OperationMode != OperationMode.Normal;
                Context      = requestHeader.Context;
                Priority     = default;
                Deadline     = DateTime.MaxValue;
            }
            else
            {
                int headerSize = istr.ReadSize();
                int startPos   = istr.Pos;

                // We use the generated code for the header body and read the rest of the header "by hand".
                var requestHeaderBody = new Ice2RequestHeaderBody(istr);
                Identity     = requestHeaderBody.Identity;
                Facet        = requestHeaderBody.Facet ?? "";
                Location     = requestHeaderBody.Location ?? Array.Empty <string>();
                Operation    = requestHeaderBody.Operation;
                IsIdempotent = requestHeaderBody.Idempotent ?? false;
                Priority     = requestHeaderBody.Priority ?? default;
                if (requestHeaderBody.Deadline < -1 || requestHeaderBody.Deadline == 0)
                {
                    throw new InvalidDataException($"received invalid deadline value {requestHeaderBody.Deadline}");
                }
                // The infinite deadline is encoded as -1 and converted to DateTime.MaxValue
                Deadline = requestHeaderBody.Deadline == -1 ?
                           DateTime.MaxValue : DateTime.UnixEpoch + TimeSpan.FromMilliseconds(requestHeaderBody.Deadline);
                Context = requestHeaderBody.Context ?? new SortedDictionary <string, string>();

                BinaryContext = istr.ReadBinaryContext();

                if (istr.Pos - startPos != headerSize)
                {
                    throw new InvalidDataException(
                              @$ "received invalid request header: expected {headerSize} bytes but read {istr.Pos - startPos
                        } bytes");
                }

                if (Location.Any(segment => segment.Length == 0))
                {
                    throw new InvalidDataException("received request with an empty location segment");
                }
            }