Refactored WebSocketServiceHost.cs

This commit is contained in:
sta 2014-08-30 11:58:16 +09:00
parent 83869d6750
commit 1a1b109508

View File

@ -29,7 +29,7 @@
#region Contributors #region Contributors
/* /*
* Contributors: * Contributors:
* Juan Manuel Lallana <juan.manuel.lallana@gmail.com> * - Juan Manuel Lallana <juan.manuel.lallana@gmail.com>
*/ */
#endregion #endregion
@ -40,8 +40,8 @@ using WebSocketSharp.Net.WebSockets;
namespace WebSocketSharp.Server namespace WebSocketSharp.Server
{ {
/// <summary> /// <summary>
/// Exposes the methods and properties used for accessing the information in a WebSocket /// Exposes the methods and properties used to access the information in a WebSocket service
/// service provided by the <see cref="HttpServer"/> or <see cref="WebSocketServer"/>. /// provided by the <see cref="HttpServer"/> or <see cref="WebSocketServer"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The WebSocketServiceHost class is an abstract class. /// The WebSocketServiceHost class is an abstract class.
@ -69,7 +69,9 @@ namespace WebSocketSharp.Server
/// <c>true</c> if the WebSocket service cleans up the inactive sessions periodically; /// <c>true</c> if the WebSocket service cleans up the inactive sessions periodically;
/// otherwise, <c>false</c>. /// otherwise, <c>false</c>.
/// </value> /// </value>
public abstract bool KeepClean { get; set; } public abstract bool KeepClean {
get; set;
}
/// <summary> /// <summary>
/// Gets the path to the WebSocket service. /// Gets the path to the WebSocket service.
@ -77,7 +79,9 @@ namespace WebSocketSharp.Server
/// <value> /// <value>
/// A <see cref="string"/> that represents the absolute path to the WebSocket service. /// A <see cref="string"/> that represents the absolute path to the WebSocket service.
/// </value> /// </value>
public abstract string Path { get; } public abstract string Path {
get;
}
/// <summary> /// <summary>
/// Gets the access to the sessions in the WebSocket service. /// Gets the access to the sessions in the WebSocket service.
@ -85,7 +89,9 @@ namespace WebSocketSharp.Server
/// <value> /// <value>
/// A <see cref="WebSocketSessionManager"/> that manages the sessions. /// A <see cref="WebSocketSessionManager"/> that manages the sessions.
/// </value> /// </value>
public abstract WebSocketSessionManager Sessions { get; } public abstract WebSocketSessionManager Sessions {
get;
}
/// <summary> /// <summary>
/// Gets the type of the WebSocket service. /// Gets the type of the WebSocket service.
@ -93,7 +99,9 @@ namespace WebSocketSharp.Server
/// <value> /// <value>
/// A <see cref="System.Type"/> that represents the type of the WebSocket service. /// A <see cref="System.Type"/> that represents the type of the WebSocket service.
/// </value> /// </value>
public abstract Type Type { get; } public abstract Type Type {
get;
}
#endregion #endregion
@ -101,8 +109,7 @@ namespace WebSocketSharp.Server
internal void StartSession (WebSocketContext context) internal void StartSession (WebSocketContext context)
{ {
var session = CreateSession (); CreateSession ().Start (context, Sessions);
session.Start (context, Sessions);
} }
#endregion #endregion
@ -125,7 +132,7 @@ namespace WebSocketSharp.Server
{ {
#region Private Fields #region Private Fields
private Func<T> _constructor; private Func<T> _initializer;
private string _path; private string _path;
private WebSocketSessionManager _sessions; private WebSocketSessionManager _sessions;
@ -133,10 +140,10 @@ namespace WebSocketSharp.Server
#region Internal Constructors #region Internal Constructors
internal WebSocketServiceHost (string path, Func<T> constructor, Logger logger) internal WebSocketServiceHost (string path, Func<T> initializer, Logger logger)
{ {
_path = HttpUtility.UrlDecode (path).TrimEndSlash (); _path = HttpUtility.UrlDecode (path).TrimEndSlash ();
_constructor = constructor; _initializer = initializer;
_sessions = new WebSocketSessionManager (logger); _sessions = new WebSocketSessionManager (logger);
} }
@ -178,7 +185,7 @@ namespace WebSocketSharp.Server
protected override WebSocketService CreateSession () protected override WebSocketService CreateSession ()
{ {
return _constructor (); return _initializer ();
} }
#endregion #endregion