Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions samples/MediaPlayerRemote/Mpris.DBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ record PlayerProperties
public string PlaybackStatus { get; set; } = default!;
public string LoopStatus { get; set; } = default!;
public double Volume { get; set; } = default!;
public double Shuffle { get; set; } = default!;
public bool Shuffle { get; set; } = default!;
public int Position { get; set; } = default!;
public double Rate { get; set; } = default!;
public double MinimumRate { get; set; } = default!;
Expand Down Expand Up @@ -848,8 +848,8 @@ private static PlayerProperties ReadProperties(ref Reader reader, List<string>?
changedList?.Add("Volume");
break;
case "Shuffle":
reader.ReadSignature("d");
props.Shuffle = reader.ReadDouble();
reader.ReadSignature("b");
props.Shuffle = reader.ReadBool();
changedList?.Add("Shuffle");
break;
case "Position":
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<VersionPrefix>0.16.1</VersionPrefix>
<DeterministicSourcePaths>true</DeterministicSourcePaths>
<DeterministicSourcePaths Condition="'$(Configuration)' == 'Release'">true</DeterministicSourcePaths>
</PropertyGroup>
</Project>
12 changes: 9 additions & 3 deletions src/Tmds.DBus.Protocol/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ internal void Connect(IMessageStream stream)

public async ValueTask ConnectAsync()
{
await ConnectCoreAsync(autoConnect: false).ConfigureAwait(false);
await ConnectCoreAsync(explicitConnect: true).ConfigureAwait(false);
}

private ValueTask<DBusConnection> ConnectCoreAsync(bool autoConnect = true)
private ValueTask<DBusConnection> ConnectCoreAsync(bool explicitConnect = false)
{
lock (_gate)
{
Expand All @@ -71,7 +71,13 @@ private ValueTask<DBusConnection> ConnectCoreAsync(bool autoConnect = true)

if (!_connectionOptions.AutoConnect)
{
if (autoConnect || _state != ConnectionState.Created)
DBusConnection? connection = _connection;
if (!explicitConnect && _state == ConnectionState.Disconnected && connection is not null)
{
throw new DisconnectedException(connection.DisconnectReason);
}

if (!explicitConnect || _state != ConnectionState.Created)
{
throw new InvalidOperationException("Can only connect once using an explicit call.");
}
Expand Down
17 changes: 17 additions & 0 deletions test/Tmds.DBus.Protocol.Tests/ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ public async Task MethodAsync()
Assert.Equal("hello world", reply);
}

[Fact]
public async Task DisconnectedException()
{
var streams = PairedMessageStream.CreatePair();
using var conn1 = new Connection("conn1-address");
conn1.Connect(streams.Item1);
using var conn2 = new Connection("conn2-address");
conn2.Connect(streams.Item2);

// Close the stream at one end.
((PairedMessageStream)streams.Item2).Close();
await Task.Yield();

var proxy = new StringOperationsProxy(conn1, "servicename");
await Assert.ThrowsAsync<DisconnectedException>(() => proxy.ConcatAsync("hello ", "world"));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down
2 changes: 1 addition & 1 deletion test/Tmds.DBus.Protocol.Tests/PairedConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ValueTask<bool> TrySendMessageAsync(MessageBuffer message)
return ValueTask.FromResult(true);
}

public void Close(Exception closeReason)
public void Close(Exception? closeReason = null)
{
TrySendMessageAsync(null!); // Use null as EOF.
}
Expand Down