diff --git a/src/Tmds.DBus.Protocol/MessageBuffer.cs b/src/Tmds.DBus.Protocol/MessageBuffer.cs index a2ac4e70..8b5178e8 100644 --- a/src/Tmds.DBus.Protocol/MessageBuffer.cs +++ b/src/Tmds.DBus.Protocol/MessageBuffer.cs @@ -1,6 +1,6 @@ namespace Tmds.DBus.Protocol; -public sealed class MessageBuffer : IDisposable +public sealed class MessageBuffer { private readonly MessageBufferPool _messagePool; @@ -25,10 +25,12 @@ internal void Init(uint serial, MessageFlags flags, UnixFdCollection? handles) Handles = handles; } - public void Dispose() => ReturnToPool(); - - public void RefHandles() => Handles?.RefHandles(); + internal void RefHandles() => Handles?.RefHandles(); + // Users should create a message using a MessageWriter + // and then hand it to the Connection class which is responsible for calling this method. + // A library user is never considered the owner of this message and therefore + // we don't provide a public method for a user to Dispose/ReturnToPool. internal void ReturnToPool() { _data.Reset(); diff --git a/src/Tmds.DBus.Protocol/MethodContext.cs b/src/Tmds.DBus.Protocol/MethodContext.cs index db8380b0..2b7d6be5 100644 --- a/src/Tmds.DBus.Protocol/MethodContext.cs +++ b/src/Tmds.DBus.Protocol/MethodContext.cs @@ -36,7 +36,7 @@ public void Reply(MessageBuffer message) { if (ReplySent || NoReplyExpected) { - message.Dispose(); + message.ReturnToPool(); if (ReplySent) { throw new InvalidOperationException("A reply has already been sent."); diff --git a/src/Tmds.DBus.Protocol/Variant.cs b/src/Tmds.DBus.Protocol/Variant.cs index fc097e52..b8f8faf6 100644 --- a/src/Tmds.DBus.Protocol/Variant.cs +++ b/src/Tmds.DBus.Protocol/Variant.cs @@ -59,7 +59,7 @@ public Variant(ulong value) _l = (long)value; _o = UInt64Type; } - internal unsafe Variant(double value) + public unsafe Variant(double value) { _l = *(long*)&value; _o = DoubleType; @@ -448,4 +448,4 @@ internal unsafe void WriteTo(ref MessageWriter writer) throw new InvalidOperationException($"Cannot write Variant of type {Type}."); } } -} \ No newline at end of file +}