Skip to content

Commit

Permalink
Merge pull request #835 from Cysharp/feature/MoveToInternal
Browse files Browse the repository at this point in the history
Move internal classes under Internal namespace
  • Loading branch information
mayuki authored Sep 19, 2024
2 parents cc5654a + 1930ac7 commit b282c8b
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace MagicOnion.Client
{
/// <summary>
/// Represents a client heartbeat received event.
/// </summary>
public readonly struct ClientHeartbeatEvent
{
/// <summary>
/// Gets the round trip time (RTT) between client and server.
/// </summary>
public TimeSpan RoundTripTime { get; }

public ClientHeartbeatEvent(long roundTripTimeMs)
{
RoundTripTime = TimeSpan.FromMilliseconds(roundTripTimeMs);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,8 @@
using MagicOnion.Internal.Buffers;
using MessagePack;

namespace MagicOnion.Client
namespace MagicOnion.Client.Internal
{
/// <summary>
/// Represents a client heartbeat received event.
/// </summary>
public readonly struct ClientHeartbeatEvent
{
/// <summary>
/// Gets the round trip time (RTT) between client and server.
/// </summary>
public TimeSpan RoundTripTime { get; }

public ClientHeartbeatEvent(long roundTripTimeMs)
{
RoundTripTime = TimeSpan.FromMilliseconds(roundTripTimeMs);
}
}

/// <summary>
/// Represents a server heartbeat received event.
/// </summary>
public readonly struct ServerHeartbeatEvent
{
/// <summary>
/// Gets the server time at when the heartbeat was sent.
/// </summary>
public DateTimeOffset ServerTime { get; }

/// <summary>
/// Gets the metadata data. The data is only available during event processing.
/// </summary>
public ReadOnlyMemory<byte> Metadata { get; }

public ServerHeartbeatEvent(long serverTimeUnixMs, ReadOnlyMemory<byte> metadata)
{
ServerTime = DateTimeOffset.FromUnixTimeMilliseconds(serverTimeUnixMs);
Metadata = metadata;
}
}

internal class StreamingHubClientHeartbeatManager : IAsyncDisposable
{
readonly object gate = new();
Expand Down Expand Up @@ -86,7 +48,7 @@ CancellationToken shutdownToken
#endif
)
{
this.timeoutTokenSource = new(
timeoutTokenSource = new(
#if NET8_0_OR_GREATER
Timeout.InfiniteTimeSpan, timeProvider
#endif
Expand All @@ -97,7 +59,7 @@ CancellationToken shutdownToken
this.onServerHeartbeatReceived = onServerHeartbeatReceived;
this.onClientHeartbeatResponseReceived = onClientHeartbeatResponseReceived;
this.synchronizationContext = synchronizationContext;
this.shutdownTokenSource = CancellationTokenSource.CreateLinkedTokenSource(shutdownToken, timeoutTokenSource.Token);
shutdownTokenSource = CancellationTokenSource.CreateLinkedTokenSource(shutdownToken, timeoutTokenSource.Token);
#if NON_UNITY
this.timeProvider = timeProvider;
#endif
Expand Down Expand Up @@ -188,7 +150,7 @@ SendOrPostCallback ProcessClientHeartbeatResponseCore(Action<ClientHeartbeatEven
_ = reader.ReadMessageType();
var (sentSequence, clientSentAt) = reader.ReadClientHeartbeatResponse();

if (sentSequence == (sequence - 1)/* NOTE: Sequence already 1 advanced.*/)
if (sentSequence == sequence - 1/* NOTE: Sequence already 1 advanced.*/)
{
// Cancel the running timeout cancellation timer.
timeoutTokenSource.CancelAfter(Timeout.InfiniteTimeSpan);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;

namespace MagicOnion.Client
namespace MagicOnion.Client.Internal
{
internal class StreamingHubResponseTaskSourcePool<T> : ObjectPool<StreamingHubResponseTaskSource<T>>
{
public static StreamingHubResponseTaskSourcePool<T> Shared { get; } = new();

public StreamingHubResponseTaskSourcePool()
: base(static () => new StreamingHubResponseTaskSource<T>())
{}
{ }

public StreamingHubResponseTaskSource<T> RentOrCreate()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace MagicOnion.Client
{
/// <summary>
/// Represents a server heartbeat received event.
/// </summary>
public readonly struct ServerHeartbeatEvent
{
/// <summary>
/// Gets the server time at when the heartbeat was sent.
/// </summary>
public DateTimeOffset ServerTime { get; }

/// <summary>
/// Gets the metadata data. The data is only available during event processing.
/// </summary>
public ReadOnlyMemory<byte> Metadata { get; }

public ServerHeartbeatEvent(long serverTimeUnixMs, ReadOnlyMemory<byte> metadata)
{
ServerTime = DateTimeOffset.FromUnixTimeMilliseconds(serverTimeUnixMs);
Metadata = metadata;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using MagicOnion.Internal;
using MagicOnion.Serialization;
using MagicOnion.Internal.Buffers;
using MagicOnion.Client.Internal;

namespace MagicOnion.Client
{
Expand Down
20 changes: 20 additions & 0 deletions src/MagicOnion.Client/ClientHeartbeatEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace MagicOnion.Client
{
/// <summary>
/// Represents a client heartbeat received event.
/// </summary>
public readonly struct ClientHeartbeatEvent
{
/// <summary>
/// Gets the round trip time (RTT) between client and server.
/// </summary>
public TimeSpan RoundTripTime { get; }

public ClientHeartbeatEvent(long roundTripTimeMs)
{
RoundTripTime = TimeSpan.FromMilliseconds(roundTripTimeMs);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,8 @@
using MagicOnion.Internal.Buffers;
using MessagePack;

namespace MagicOnion.Client
namespace MagicOnion.Client.Internal
{
/// <summary>
/// Represents a client heartbeat received event.
/// </summary>
public readonly struct ClientHeartbeatEvent
{
/// <summary>
/// Gets the round trip time (RTT) between client and server.
/// </summary>
public TimeSpan RoundTripTime { get; }

public ClientHeartbeatEvent(long roundTripTimeMs)
{
RoundTripTime = TimeSpan.FromMilliseconds(roundTripTimeMs);
}
}

/// <summary>
/// Represents a server heartbeat received event.
/// </summary>
public readonly struct ServerHeartbeatEvent
{
/// <summary>
/// Gets the server time at when the heartbeat was sent.
/// </summary>
public DateTimeOffset ServerTime { get; }

/// <summary>
/// Gets the metadata data. The data is only available during event processing.
/// </summary>
public ReadOnlyMemory<byte> Metadata { get; }

public ServerHeartbeatEvent(long serverTimeUnixMs, ReadOnlyMemory<byte> metadata)
{
ServerTime = DateTimeOffset.FromUnixTimeMilliseconds(serverTimeUnixMs);
Metadata = metadata;
}
}

internal class StreamingHubClientHeartbeatManager : IAsyncDisposable
{
readonly object gate = new();
Expand Down Expand Up @@ -86,7 +48,7 @@ CancellationToken shutdownToken
#endif
)
{
this.timeoutTokenSource = new(
timeoutTokenSource = new(
#if NET8_0_OR_GREATER
Timeout.InfiniteTimeSpan, timeProvider
#endif
Expand All @@ -97,7 +59,7 @@ CancellationToken shutdownToken
this.onServerHeartbeatReceived = onServerHeartbeatReceived;
this.onClientHeartbeatResponseReceived = onClientHeartbeatResponseReceived;
this.synchronizationContext = synchronizationContext;
this.shutdownTokenSource = CancellationTokenSource.CreateLinkedTokenSource(shutdownToken, timeoutTokenSource.Token);
shutdownTokenSource = CancellationTokenSource.CreateLinkedTokenSource(shutdownToken, timeoutTokenSource.Token);
#if NON_UNITY
this.timeProvider = timeProvider;
#endif
Expand Down Expand Up @@ -188,7 +150,7 @@ SendOrPostCallback ProcessClientHeartbeatResponseCore(Action<ClientHeartbeatEven
_ = reader.ReadMessageType();
var (sentSequence, clientSentAt) = reader.ReadClientHeartbeatResponse();

if (sentSequence == (sequence - 1)/* NOTE: Sequence already 1 advanced.*/)
if (sentSequence == sequence - 1/* NOTE: Sequence already 1 advanced.*/)
{
// Cancel the running timeout cancellation timer.
timeoutTokenSource.CancelAfter(Timeout.InfiniteTimeSpan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;

namespace MagicOnion.Client
namespace MagicOnion.Client.Internal
{
internal class StreamingHubResponseTaskSourcePool<T> : ObjectPool<StreamingHubResponseTaskSource<T>>
{
public static StreamingHubResponseTaskSourcePool<T> Shared { get; } = new();

public StreamingHubResponseTaskSourcePool()
: base(static () => new StreamingHubResponseTaskSource<T>())
{}
{ }

public StreamingHubResponseTaskSource<T> RentOrCreate()
{
Expand Down
26 changes: 26 additions & 0 deletions src/MagicOnion.Client/ServerHeartbeatEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace MagicOnion.Client
{
/// <summary>
/// Represents a server heartbeat received event.
/// </summary>
public readonly struct ServerHeartbeatEvent
{
/// <summary>
/// Gets the server time at when the heartbeat was sent.
/// </summary>
public DateTimeOffset ServerTime { get; }

/// <summary>
/// Gets the metadata data. The data is only available during event processing.
/// </summary>
public ReadOnlyMemory<byte> Metadata { get; }

public ServerHeartbeatEvent(long serverTimeUnixMs, ReadOnlyMemory<byte> metadata)
{
ServerTime = DateTimeOffset.FromUnixTimeMilliseconds(serverTimeUnixMs);
Metadata = metadata;
}
}
}
1 change: 1 addition & 0 deletions src/MagicOnion.Client/StreamingHubClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using MagicOnion.Internal;
using MagicOnion.Serialization;
using MagicOnion.Internal.Buffers;
using MagicOnion.Client.Internal;

namespace MagicOnion.Client
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Buffers;
using System.Diagnostics;
using System.Threading.Channels;
using MagicOnion.Client.Internal;
using MagicOnion.Internal;
using Microsoft.Extensions.Time.Testing;

Expand Down

0 comments on commit b282c8b

Please sign in to comment.