/// <summary>Creates a new IncomingResponse Frame</summary> /// <param name="communicator">The communicator to use when initializing the stream.</param> /// <param name="payload">The frame data as an array segment.</param> public IncomingResponseFrame(Communicator communicator, ArraySegment <byte> payload) { _communicator = communicator; byte replyStatus = payload[0]; if (replyStatus > 7) { throw new InvalidDataException( $"received ice1 response frame with unknown reply status `{replyStatus}'"); } ReplyStatus = (ReplyStatus)replyStatus; Payload = payload; if (ReplyStatus == ReplyStatus.UserException || ReplyStatus == ReplyStatus.OK) { int size = InputStream.ReadInt(Payload.Slice(1, 4)); if (size != Payload.Count - 1) { throw new InvalidDataException($"invalid encapsulation size: `{size}'"); } Encoding = new Encoding(payload[5], payload[6]); } else { Encoding = Encoding.V1_1; } }
public IPEndpoint(TransportInstance instance, Ice.InputStream s) { Instance = instance; Host = s.ReadString(); Port = s.ReadInt(); SourceAddr = null; ConnectionId_ = ""; }
private static void PrintBatchRequest(System.IO.StringWriter s, Ice.InputStream str) { int batchRequestNum = str.ReadInt(); s.Write("\nnumber of requests = " + batchRequestNum); for (int i = 0; i < batchRequestNum; ++i) { s.Write("\nrequest #" + i + ':'); PrintRequestHeader(s, str); } }
private static void PrintRequest(System.IO.StringWriter s, Ice.InputStream str) { int requestId = str.ReadInt(); s.Write("\nrequest id = " + requestId); if (requestId == 0) { s.Write(" (oneway)"); } PrintRequestHeader(s, str); }
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); }
private static void PrintReply(System.IO.StringWriter s, Ice.InputStream str) { int requestId = str.ReadInt(); s.Write("\nrequest id = " + requestId); var replyStatus = (ReplyStatus)str.ReadByte(); s.Write($"\nreply status = {replyStatus}"); if (replyStatus == ReplyStatus.OK || replyStatus == ReplyStatus.UserException) { _ = str.SkipEncapsulation(); s.Write("\nencoding = "); } }
private protected IPEndpoint(TransportInstance instance, InputStream s) { Instance = instance; Host = s.ReadString(); Port = s.ReadInt(); }
private static Ice1Definitions.MessageType PrintHeader(System.IO.StringWriter s, Ice.InputStream str) { try { str.ReadByte(); // Don't bother printing the magic number str.ReadByte(); str.ReadByte(); str.ReadByte(); /* byte pMajor = */ str.ReadByte(); /* byte pMinor = */ str.ReadByte(); //s.Write("\nprotocol version = " + (int)pMajor + "." + (int)pMinor); /* byte eMajor = */ str.ReadByte(); /* byte eMinor = */ str.ReadByte(); //s.Write("\nencoding version = " + (int)eMajor + "." + (int)eMinor); var type = (Ice1Definitions.MessageType)str.ReadByte(); s.Write("\nmessage type = " + (int)type + " (" + GetMessageTypeAsString(type) + ')'); byte compress = str.ReadByte(); s.Write("\ncompression status = " + (int)compress + ' '); switch (compress) { case 0: { s.Write("(not compressed; do not compress response, if any)"); break; } case 1: { s.Write("(not compressed; compress response, if any)"); break; } case 2: { s.Write("(compressed; compress response, if any)"); break; } default: { s.Write("(unknown)"); break; } } int size = str.ReadInt(); s.Write("\nmessage size = " + size); return(type); } catch (System.IO.IOException) { Debug.Assert(false); return(0); } }
internal TcpEndpoint(TransportInstance instance, InputStream s) : base(instance, s) { Timeout = s.ReadInt(); HasCompressionFlag = s.ReadBool(); }
public TcpEndpoint(TransportInstance instance, Ice.InputStream s) : base(instance, s) { _timeout = s.ReadInt(); _compress = s.ReadBool(); }