Skip to content

Commit

Permalink
Refactorings.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmds committed Jun 19, 2024
1 parent 7561068 commit bb18b6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Tmds.DBus.Protocol/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,25 +296,24 @@ private static Connection CreateConnection(ref Connection? field, string? addres

public bool TrySendMessage(MessageBuffer message)
{
bool messageSent = false;
try
{
DBusConnection? connection = GetConnection(ifConnected: true);
if (connection is null)
{
message.ReturnToPool();
return false;
}
else
if (connection is not null)
{
RefHandles(message);
connection.SendMessage(message);
return true;
messageSent = true;
}
return messageSent;
}
catch
finally
{
message.ReturnToPool();
throw;
if (!messageSent)
{
message.ReturnToPool();
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Tmds.DBus.Protocol/SocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ private static unsafe int sendmsg(Socket socket, ReadOnlyMemory<byte> buffer, Un
finally
{
if (refAdded)
{
handle.DangerousRelease();
}
}
}
}
Expand Down Expand Up @@ -175,7 +177,9 @@ private static unsafe int recvmsg(Socket socket, Memory<byte> buffer, UnixFdColl
finally
{
if (refAdded)
{
handle.DangerousRelease();
}
}
}
}
Expand Down

0 comments on commit bb18b6a

Please sign in to comment.