示例#1
0
 internal TcpEndpoint(InputStream istr, Transport transport, Protocol protocol)
     : base(istr, protocol)
 {
     Transport          = transport;
     Timeout            = istr.ReadInt();
     HasCompressionFlag = istr.ReadBool();
 }
示例#2
0
 private protected IPEndpoint(InputStream istr, Communicator communicator, Protocol protocol)
     : base(protocol)
 {
     Communicator = communicator;
     Host         = istr.ReadString();
     Port         = istr.ReadInt();
 }
示例#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);
示例#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);
        }
示例#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);
示例#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);
示例#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 !));
        }
示例#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();
            }
        }
示例#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);
示例#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;
        }
示例#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());
     }
 }
示例#12
0
文件: IPEndpoint.cs 项目: wandec/ice
 private protected IPEndpoint(Communicator communicator, InputStream istr)
 {
     Communicator = communicator;
     Host         = istr.ReadString();
     Port         = istr.ReadInt();
 }
示例#13
0
 private protected IPEndpoint(TransportInstance instance, InputStream s)
 {
     Instance = instance;
     Host     = s.ReadString();
     Port     = s.ReadInt();
 }
示例#14
0
 internal TcpEndpoint(TransportInstance instance, InputStream s) :
     base(instance, s)
 {
     Timeout            = s.ReadInt();
     HasCompressionFlag = s.ReadBool();
 }
示例#15
0
 internal TcpEndpoint(Communicator communicator, InputStream istr) : base(communicator, istr)
 {
     Timeout            = istr.ReadInt();
     HasCompressionFlag = istr.ReadBool();
 }