/// <summary>Creates a new response frame that represents "success" with a void return value. The returned /// frame is complete and no additional data can be included in its payload.</summary> /// <param name="current">The current parameter holds decoded header data and other information about the /// request currently dispatched.</param> /// <returns>An <see cref="Ice.OutputStream"/> that holds the new frame.</returns> public static Ice.OutputStream CreateEmptyResponseFrame(Ice.Current current) { var ostr = new Ice.OutputStream(current.Adapter.Communicator, Ice.Util.CurrentProtocolEncoding); ostr.WriteBlob(Protocol.replyHdr); ostr.WriteInt(current.RequestId); ostr.WriteByte(ReplyStatus.replyOK); ostr.WriteEmptyEncapsulation(current.Encoding); return(ostr); }
/// <summary>Starts a new response frame and the encapsulation in that frame. This frame encodes a "success" /// response.</summary> /// <param name="current">The current parameter holds decoded header data and other information about the /// request currently dispatched.</param> /// <param name="format">The Slice format (Compact or Sliced) used by the encapsulation.</param> /// <returns>An <see cref="Ice.OutputStream"/> that holds the new frame.</returns> public static Ice.OutputStream StartResponseFrame(Ice.Current current, Ice.FormatType?format = null) { var ostr = new Ice.OutputStream(current.Adapter.Communicator, Ice.Util.CurrentProtocolEncoding); ostr.WriteBlob(Protocol.replyHdr); ostr.WriteInt(current.RequestId); ostr.WriteByte(ReplyStatus.replyOK); ostr.StartEncapsulation(current.Encoding, format); return(ostr); }
/// <summary>Starts a new response frame and the encapsulation in that frame. This frame encodes a "failure" /// response.</summary> /// <param name="current">The current parameter holds decoded header data and other information about the /// request currently dispatched.</param> /// <returns>An <see cref="Ice.OutputStream"/> that holds the new frame.</returns> public static Ice.OutputStream StartFailureResponseFrame(Ice.Current current) { var ostr = new Ice.OutputStream(current.Adapter.Communicator, Ice.Util.CurrentProtocolEncoding); ostr.WriteBlob(Protocol.replyHdr); ostr.WriteInt(current.RequestId); ostr.WriteByte(ReplyStatus.replyUserException); // Exceptions are always marshaled in the sliced format: ostr.StartEncapsulation(current.Encoding, FormatType.SlicedFormat); return(ostr); }
internal static List <ArraySegment <byte> >?Compress( List <ArraySegment <byte> > data, int size, int headerSize, int compressionLevel) { Debug.Assert(IsLoaded); // Compress the message body, but not the header. int decompressedLen = size - headerSize; // Compress the message body, but not the header. byte[] compressed = new byte[(int)((decompressedLen * 1.01) + 600)]; // Prevent GC from moving the byte array, this allow to take the object address // and pass it to bzip2 calls. var compressedHandle = GCHandle.Alloc(compressed, GCHandleType.Pinned); var bzStream = new BZStream(compressedHandle.AddrOfPinnedObject(), (uint)compressed.Length); ArraySegment <byte> headerSegment = data[0]; try { BZ2_bzCompressInit(ref bzStream, compressionLevel, 0, 0); // Slice the first segment to skip the header, the header is never compressed Debug.Assert(headerSegment.Offset == 0); data[0] = headerSegment.Slice(headerSize); BzStatus rc = BzStatus.RunOk; for (int i = 0; rc == BzStatus.RunOk && i < data.Count; i++) { ArraySegment <byte> segment = data[i]; var segmentHandle = GCHandle.Alloc(segment.Array, GCHandleType.Pinned); bzStream.NextIn = segmentHandle.AddrOfPinnedObject() + segment.Offset; bzStream.AvailIn = (uint)segment.Count; Debug.Assert(bzStream.AvailIn > 0); do { rc = (BzStatus)BZ2_bzCompress(ref bzStream, (int)BzAction.Run); }while (rc == BzStatus.RunOk && bzStream.AvailIn > 0); segmentHandle.Free(); } if (rc != BzStatus.RunOk) { throw new TransportException($"bzip2 compression failed: {rc}"); } do { rc = (BzStatus)BZ2_bzCompress(ref bzStream, (int)BzAction.Finish); }while (rc == BzStatus.FinishOk); if (rc != BzStatus.StreamEnd) { throw new TransportException($"bzip2 compression failed: {rc}"); } int compressedLen = compressed.Length - (int)bzStream.AvailOut; // Don't bother if the compressed data is larger than the decompressed data. if (compressedLen >= decompressedLen) { return(null); } // Copy the header from the decompressed stream to the compressed one, // we use headerSize + 4 to ensure there is room for the size of the // decompressed stream in the first segment. ArraySegment <byte> compressedHeader = new byte[headerSize + 4]; headerSegment.AsSpan(0, headerSize).CopyTo(compressedHeader); int compressedSize = compressedLen + compressedHeader.Count; // Write the compression status and the size of the compressed // stream into the header. compressedHeader[9] = 2; OutputStream.WriteInt(compressedSize, compressedHeader.AsSpan(10, 4)); // Write the compression status and size of the compressed stream // into the header of the decompressed stream -- we need this to // trace requests correctly. headerSegment[9] = 2; OutputStream.WriteInt(compressedSize, headerSegment.AsSpan(10, 4)); // Add the size of the decompressed stream before the message body. OutputStream.WriteInt(size, compressedHeader.AsSpan(headerSize, 4)); return(new List <ArraySegment <byte> >(2) { compressedHeader, new ArraySegment <byte>(compressed, 0, compressedLen) }); } finally { // Restore the first segment that was Sliced above to skip the header data[0] = headerSegment; BZ2_bzCompressEnd(ref bzStream); compressedHandle.Free(); } }
public override void IceWritePayload(OutputStream ostr) { ostr.WriteString(Host); ostr.WriteInt(Port); }
public override void IceWriteImpl(OutputStream s) { s.WriteString(Host); s.WriteInt(Port); }
public override void IceWriteImpl(OutputStream s) { base.IceWriteImpl(s); s.WriteInt(Timeout); s.WriteBool(HasCompressionFlag); }
///<summary>Creates a response frame that represents "failure" and contains an exception. The returned frame is /// complete and no additional data can be included in its payload.</summary> /// <param name="exception">The exception to marshal into the frame.</param> /// <param name="current">The current parameter holds decoded header data and other information about the /// request currently dispatched.</param> /// <returns>An <see cref="Ice.OutputStream"/> that holds the new frame.</returns> public static Ice.OutputStream CreateFailureResponseFrame(System.Exception exception, Ice.Current current) { var ostr = new Ice.OutputStream(current.Adapter.Communicator, Ice.Util.CurrentProtocolEncoding); ostr.WriteBlob(Protocol.replyHdr); ostr.WriteInt(current.RequestId); try { throw exception; } catch (Ice.RequestFailedException ex) { if (ex.Id.Name == null || ex.Id.Name.Length == 0) { ex.Id = current.Id; } if (ex.Facet == null || ex.Facet.Length == 0) { ex.Facet = current.Facet; } if (ex.Operation == null || ex.Operation.Length == 0) { ex.Operation = current.Operation; } if (ex is Ice.ObjectNotExistException) { ostr.WriteByte(ReplyStatus.replyObjectNotExist); } else if (ex is Ice.FacetNotExistException) { ostr.WriteByte(ReplyStatus.replyFacetNotExist); } else if (ex is Ice.OperationNotExistException) { ostr.WriteByte(ReplyStatus.replyOperationNotExist); } else { Debug.Assert(false); } ex.Id.IceWrite(ostr); // For compatibility with the old FacetPath. if (ex.Facet == null || ex.Facet.Length == 0) { ostr.WriteStringSeq(Array.Empty <string>()); } else { string[] facetPath2 = { ex.Facet }; ostr.WriteStringSeq(facetPath2); } ostr.WriteString(ex.Operation); } catch (Ice.UnknownLocalException ex) { ostr.WriteByte(ReplyStatus.replyUnknownLocalException); ostr.WriteString(ex.Unknown); } catch (Ice.UnknownUserException ex) { ostr.WriteByte(ReplyStatus.replyUnknownUserException); ostr.WriteString(ex.Unknown); } catch (Ice.UnknownException ex) { ostr.WriteByte(ReplyStatus.replyUnknownException); ostr.WriteString(ex.Unknown); } catch (Ice.UserException ex) { ostr.WriteByte(ReplyStatus.replyUserException); // Exceptions are always marshaled in the sliced format: ostr.StartEncapsulation(current.Encoding, FormatType.SlicedFormat); ostr.WriteException(ex); ostr.EndEncapsulation(); } catch (Ice.Exception ex) { ostr.WriteByte(ReplyStatus.replyUnknownLocalException); ostr.WriteString(ex.ice_id() + "\n" + ex.StackTrace); } catch (System.Exception ex) { ostr.WriteByte(ReplyStatus.replyUnknownException); ostr.WriteString(ex.ToString()); } return(ostr); }
public override void IceWritePayload(OutputStream ostr) { base.IceWritePayload(ostr); ostr.WriteInt(Timeout); ostr.WriteBool(HasCompressionFlag); }