Skip to content

Commit 8759aa2

Browse files
authored
SignalR additional xml docs (#7980)
Reviewed our xml docs as both ramping back up after leave and docathon. Things look pretty good, added a few things to some public methods.
2 parents b2a58ab + 22e706c commit 8759aa2

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,40 @@ public partial class HubConnection
6363
private ConnectionState _connectionState;
6464
private int _serverProtocolMinorVersion;
6565

66+
/// <summary>
67+
/// Occurs when the connection is closed. The connection could be closed due to an error or due to either the server or client intentionally
68+
/// closing the connection without error.
69+
/// </summary>
70+
/// <remarks>
71+
/// If this event was triggered from a connection error, the <see cref="Exception"/> that occurred will be passed in as the
72+
/// sole argument to this handler. If this event was triggered intentionally by either the client or server, then
73+
/// the argument will be <see langword="null"/>.
74+
/// </remarks>
75+
/// <example>
76+
/// The following example attaches a handler to the <see cref="Closed"/> event, and checks the provided argument to determine
77+
/// if there was an error:
78+
///
79+
/// <code>
80+
/// connection.Closed += (exception) =>
81+
/// {
82+
/// if (exception == null)
83+
/// {
84+
/// Console.WriteLine("Connection closed without error.");
85+
/// }
86+
/// else
87+
/// {
88+
/// Console.WriteLine($"Connection closed due to an error: {exception.Message}");
89+
/// }
90+
/// };
91+
/// </code>
92+
/// </example>
6693
public event Func<Exception, Task> Closed;
6794

6895
// internal for testing purposes
6996
internal TimeSpan TickRate { get; set; } = TimeSpan.FromSeconds(1);
7097

7198
/// <summary>
72-
/// Gets or sets the server timeout interval for the connection.
99+
/// Gets or sets the server timeout interval for the connection.
73100
/// </summary>
74101
/// <remarks>
75102
/// The client times out if it hasn't heard from the server for `this` long.
@@ -510,7 +537,7 @@ private void LaunchStreams(Dictionary<string, object> readers, CancellationToken
510537
}
511538
}
512539

513-
// this is called via reflection using the `_sendStreamItems` field
540+
// this is called via reflection using the `_sendStreamItems` field
514541
private async Task SendStreamItems<T>(string streamId, ChannelReader<T> reader, CancellationToken token)
515542
{
516543
Log.StartingStream(_logger, streamId);
@@ -849,7 +876,7 @@ private async Task HandshakeAsync(ConnectionState startingConnectionState, Cance
849876
}
850877
}
851878
}
852-
879+
853880
// shutdown if we're unable to read handshake
854881
// Ignore HubException because we throw it when we receive a handshake response with an error
855882
// And because we already have the error, we don't need to log that the handshake failed
@@ -1139,7 +1166,7 @@ public void Dispose()
11391166
private class InvocationHandlerList
11401167
{
11411168
private readonly List<InvocationHandler> _invocationHandlers;
1142-
// A lazy cached copy of the handlers that doesn't change for thread safety.
1169+
// A lazy cached copy of the handlers that doesn't change for thread safety.
11431170
// Adding or removing a handler sets this to null.
11441171
private InvocationHandler[] _copiedHandlers;
11451172

src/SignalR/common/Http.Connections/src/HttpConnectionContextExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ namespace Microsoft.AspNetCore.Http.Connections
99
{
1010
public static class HttpConnectionContextExtensions
1111
{
12+
/// <summary>
13+
/// Gets the <see cref="HttpContext"/> associated with the connection, if there is one.
14+
/// </summary>
15+
/// <param name="connection">The <see cref="ConnectionContext"/> representing the connection.</param>
16+
/// <returns>The <see cref="HttpContext"/> associated with the connection, or <see langword="null"/> if the connection is not HTTP-based.</returns>
17+
/// <remarks>
18+
/// SignalR connections can run on top of HTTP transports like WebSockets or Long Polling, or other non-HTTP transports. As a result,
19+
/// this method can sometimes return <see langword="null"/> depending on the configuration of your application.
20+
/// </remarks>
1221
public static HttpContext GetHttpContext(this ConnectionContext connection)
1322
{
1423
return connection.Features.Get<IHttpContextFeature>()?.HttpContext;

src/SignalR/common/SignalR.Common/src/HubException.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ namespace Microsoft.AspNetCore.SignalR
99
/// <summary>
1010
/// The exception thrown from a hub when an error occurs.
1111
/// </summary>
12+
/// <remarks>
13+
/// Exceptions often contain sensitive information, such as connection information. Because of this, SignalR does not expose the details
14+
/// of exceptions that occur on the server to the client. However, instances of <see cref="HubException"/> <b>are</b> sent to the client.
15+
/// </remarks>
1216
[Serializable]
1317
public class HubException : Exception
1418
{

src/SignalR/server/Core/src/HubConnectionContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
namespace Microsoft.AspNetCore.SignalR
2121
{
22+
/// <summary>
23+
/// Encapsulates all information about an individual connection to a SignalR Hub.
24+
/// </summary>
2225
public class HubConnectionContext
2326
{
2427
private static readonly Action<object> _cancelReader = state => ((PipeReader)state).CancelPendingRead();

0 commit comments

Comments
 (0)