Esempio n. 1
0
 internal TcpEndpoint(InputStream istr, Transport transport, Protocol protocol)
     : base(istr, protocol)
 {
     Transport          = transport;
     Timeout            = istr.ReadInt();
     HasCompressionFlag = istr.ReadBool();
 }
Esempio n. 2
0
 private protected IPEndpoint(InputStream istr, Communicator communicator, Protocol protocol)
     : base(protocol)
 {
     Communicator = communicator;
     Host         = istr.ReadString();
     Port         = istr.ReadInt();
 }
Esempio n. 3
0
 internal static void TraceFrame(Communicator communicator, ReadOnlySpan <byte> header,
                                 IncomingResponseFrame frame) =>
 TraceResponse(
     "received response",
     communicator,
     header[8],                                // Message Type
     header[9],                                // Compression Status
     InputStream.ReadInt(header.Slice(10, 4)), // Request size
     InputStream.ReadInt(header.Slice(14, 4)), // Request-Id,
     frame.ReplyStatus,
     frame.Encoding);
Esempio n. 4
0
        internal static ArraySegment <byte> Decompress(ArraySegment <byte> compressed, int headerSize, int messageSizeMax)
        {
            Debug.Assert(IsLoaded);
            int decompressedSize = InputStream.ReadInt(compressed.AsSpan(headerSize, 4));

            if (decompressedSize <= headerSize)
            {
                throw new InvalidDataException(
                          $"received compressed ice1 frame with a decompressed size of only {decompressedSize} bytes");
            }
            if (decompressedSize > messageSizeMax)
            {
                throw new InvalidDataException(
                          $"decompressed size of {decompressedSize} bytes is greater than Ice.MessageSizeMax value");
            }

            byte[] decompressed = new byte[decompressedSize];

            // Prevent GC from moving the byte array, this allow to take the object address
            // and pass it to bzip2 calls.
            var decompressedHandle = GCHandle.Alloc(decompressed, GCHandleType.Pinned);
            var compressedHandle   = GCHandle.Alloc(compressed.Array, GCHandleType.Pinned);
            var bzStream           = new BZStream(decompressedHandle.AddrOfPinnedObject() + headerSize,
                                                  (uint)(decompressedSize - headerSize));

            BzStatus rc;

            try
            {
                rc = (BzStatus)BZ2_bzDecompressInit(ref bzStream, 0, 0);
                if (rc != BzStatus.Ok)
                {
                    throw new TransportException($"bzip2 decompression failed: {rc}");
                }

                bzStream.NextIn  = compressedHandle.AddrOfPinnedObject() + compressed.Offset + headerSize + 4;
                bzStream.AvailIn = (uint)(compressed.Count - headerSize - 4);
                rc = (BzStatus)BZ2_bzDecompress(ref bzStream);
                if (rc != BzStatus.StreamEnd)
                {
                    throw new TransportException($"bzip2 decompression failed: {rc}");
                }
            }
            finally
            {
                rc = (BzStatus)BZ2_bzDecompressEnd(ref bzStream);
                Debug.Assert(rc == BzStatus.Ok);
                decompressedHandle.Free();
                compressedHandle.Free();
            }
            compressed.AsSpan(0, headerSize).CopyTo(decompressed);
            return(decompressed);
        }
Esempio n. 5
0
 internal static void TraceFrame(
     Communicator communicator,
     ReadOnlySpan <byte> header,
     IncomingResponseFrame frame) =>
 TraceResponse(
     "received response",
     communicator,
     frame.Protocol,
     header[8],                                                                          // Frame type
     header[9],                                                                          // Compression Status
     InputStream.ReadFixedLengthSize(frame.Protocol.GetEncoding(), header.Slice(10, 4)), // Request size
     InputStream.ReadInt(header.Slice(14, 4)),                                           // Request-Id,
     frame.ReplyStatus,
     frame.Encoding);
Esempio n. 6
0
 internal static void TraceFrame(Communicator communicator, ReadOnlySpan <byte> header,
                                 IncomingRequestFrame frame) =>
 TraceRequest(
     "received request",
     communicator,
     header[8],                                // Message Type
     header[9],                                // Compression Status
     InputStream.ReadInt(header.Slice(10, 4)), // Request size
     InputStream.ReadInt(header.Slice(14, 4)), // Request-Id,
     frame.Identity,
     frame.Facet,
     frame.Operation,
     frame.IsIdempotent,
     frame.Context,
     frame.Encoding);
Esempio n. 7
0
        internal static new WSEndpoint CreateIce1Endpoint(Transport transport, InputStream istr)
        {
            Debug.Assert(transport == Transport.WS || transport == Transport.WSS);

            string host     = istr.ReadString();
            ushort port     = ReadPort(istr);
            var    timeout  = TimeSpan.FromMilliseconds(istr.ReadInt());
            bool   compress = istr.ReadBool();
            string resource = istr.ReadString();

            string[] options = resource == "/" ? Array.Empty <string>() : new string[] { resource };

            return(new WSEndpoint(new EndpointData(transport, host, port, options),
                                  timeout,
                                  compress,
                                  istr.Communicator !));
        }
Esempio n. 8
0
        // Constructor for unmarshaling.
        private protected IPEndpoint(InputStream istr, Communicator communicator, Protocol protocol)
            : base(communicator, protocol)
        {
            Host = istr.ReadString();

            if (protocol == Protocol.Ice1)
            {
                checked
                {
                    Port = (ushort)istr.ReadInt();
                }
            }
            else
            {
                Port = istr.ReadUShort();
            }
        }
Esempio n. 9
0
 internal static void TraceFrame(
     Communicator communicator,
     ReadOnlySpan <byte> header,
     OutgoingRequestFrame frame) =>
 TraceRequest(
     "sending request",
     communicator,
     frame.Protocol,
     header[8],                                                                          // Frame type
     header[9],                                                                          // Compression Status
     InputStream.ReadFixedLengthSize(frame.Protocol.GetEncoding(), header.Slice(10, 4)), // Request size
     InputStream.ReadInt(header.Slice(14, 4)),                                           // Request-Id
     frame.Identity,
     frame.Facet,
     frame.Operation,
     frame.IsIdempotent,
     frame.Context,
     frame.Encoding);
Esempio n. 10
0
        // Constructor for unmarshaling.
        private protected IPEndpoint(InputStream istr, Communicator communicator, Protocol protocol)
            : base(communicator, protocol)
        {
            Debug.Assert(protocol == Protocol.Ice1 || protocol == Protocol.Ice2);
            Host = istr.ReadString();

            if (protocol == Protocol.Ice1)
            {
                checked
                {
                    Port = (ushort)istr.ReadInt();
                }
            }
            else
            {
                Port = istr.ReadUShort();
            }
            SourceAddress = communicator.DefaultSourceAddress;
        }
Esempio n. 11
0
 // Constructor for unmarshaling
 internal TcpEndpoint(
     InputStream istr,
     Communicator communicator,
     Transport transport,
     Protocol protocol,
     bool mostDerived = true)
     : base(istr, communicator, protocol)
 {
     Transport = transport;
     if (protocol == Protocol.Ice1)
     {
         Timeout            = TimeSpan.FromMilliseconds(istr.ReadInt());
         HasCompressionFlag = istr.ReadBool();
     }
     else if (mostDerived)
     {
         SkipUnknownOptions(istr, istr.ReadSize());
     }
 }
Esempio n. 12
0
 private protected IPEndpoint(Communicator communicator, InputStream istr)
 {
     Communicator = communicator;
     Host         = istr.ReadString();
     Port         = istr.ReadInt();
 }
Esempio n. 13
0
 private protected IPEndpoint(TransportInstance instance, InputStream s)
 {
     Instance = instance;
     Host     = s.ReadString();
     Port     = s.ReadInt();
 }
Esempio n. 14
0
 internal TcpEndpoint(TransportInstance instance, InputStream s) :
     base(instance, s)
 {
     Timeout            = s.ReadInt();
     HasCompressionFlag = s.ReadBool();
 }
Esempio n. 15
0
 internal TcpEndpoint(Communicator communicator, InputStream istr) : base(communicator, istr)
 {
     Timeout            = istr.ReadInt();
     HasCompressionFlag = istr.ReadBool();
 }