Skip to content

Commit

Permalink
Protocol: [breaking] remove MessageBuffer.Dispose to avoid ownership …
Browse files Browse the repository at this point in the history
…ambiguity. (#293)
  • Loading branch information
tmds authored Jun 18, 2024
1 parent 1601490 commit b447942
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Tmds.DBus.Protocol/MessageBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Tmds.DBus.Protocol;

public sealed class MessageBuffer : IDisposable
public sealed class MessageBuffer
{
private readonly MessageBufferPool _messagePool;

Expand All @@ -25,8 +25,10 @@ internal void Init(uint serial, MessageFlags flags, UnixFdCollection? handles)
Handles = handles;
}

public void Dispose() => ReturnToPool();

// 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();
Expand Down
2 changes: 1 addition & 1 deletion src/Tmds.DBus.Protocol/MethodContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down

0 comments on commit b447942

Please sign in to comment.