Refactored a few for WebSocketBehavior.cs

This commit is contained in:
sta 2015-04-18 17:42:28 +09:00
parent 1eabd45f24
commit 4876461209

View File

@ -51,7 +51,7 @@ namespace WebSocketSharp.Server
private Func<string, bool> _originValidator; private Func<string, bool> _originValidator;
private string _protocol; private string _protocol;
private WebSocketSessionManager _sessions; private WebSocketSessionManager _sessions;
private DateTime _start; private DateTime _startTime;
private WebSocket _websocket; private WebSocket _websocket;
#endregion #endregion
@ -63,7 +63,7 @@ namespace WebSocketSharp.Server
/// </summary> /// </summary>
protected WebSocketBehavior () protected WebSocketBehavior ()
{ {
_start = DateTime.MaxValue; _startTime = DateTime.MaxValue;
} }
#endregion #endregion
@ -79,9 +79,7 @@ namespace WebSocketSharp.Server
/// </value> /// </value>
protected Logger Log { protected Logger Log {
get { get {
return _websocket != null return _websocket != null ? _websocket.Log : null;
? _websocket.Log
: null;
} }
} }
@ -103,10 +101,10 @@ namespace WebSocketSharp.Server
#region Public Properties #region Public Properties
/// <summary> /// <summary>
/// Gets the information in the current connection request to the WebSocket service. /// Gets the information in a connection request to the WebSocket service.
/// </summary> /// </summary>
/// <value> /// <value>
/// A <see cref="WebSocketContext"/> that provides the access to the current connection request, /// A <see cref="WebSocketContext"/> that provides the access to the connection request,
/// or <see langword="null"/> if the WebSocket connection isn't established. /// or <see langword="null"/> if the WebSocket connection isn't established.
/// </value> /// </value>
public WebSocketContext Context { public WebSocketContext Context {
@ -116,12 +114,12 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Gets or sets the delegate called to validate the HTTP cookies included in a connection /// Gets or sets the delegate called to validate the HTTP cookies included in
/// request to the WebSocket service. /// a connection request to the WebSocket service.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The delegate is called when the <see cref="WebSocket"/> used in the current session /// The delegate is called when the <see cref="WebSocket"/> used in the session validates
/// validates the connection request. /// the connection request.
/// </remarks> /// </remarks>
/// <value> /// <value>
/// <para> /// <para>
@ -148,10 +146,10 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Gets the unique ID of the current session. /// Gets the unique ID of a session.
/// </summary> /// </summary>
/// <value> /// <value>
/// A <see cref="string"/> that represents the unique ID of the current session, /// A <see cref="string"/> that represents the unique ID of the session,
/// or <see langword="null"/> if the WebSocket connection isn't established. /// or <see langword="null"/> if the WebSocket connection isn't established.
/// </value> /// </value>
public string ID { public string ID {
@ -179,12 +177,12 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Gets or sets the delegate called to validate the Origin header included in a connection /// Gets or sets the delegate called to validate the Origin header included in
/// request to the WebSocket service. /// a connection request to the WebSocket service.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The delegate is called when the <see cref="WebSocket"/> used in the current session /// The delegate is called when the <see cref="WebSocket"/> used in the session validates
/// validates the connection request. /// the connection request.
/// </remarks> /// </remarks>
/// <value> /// <value>
/// <para> /// <para>
@ -210,7 +208,7 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Gets or sets the WebSocket subprotocol used in the current session. /// Gets or sets the WebSocket subprotocol used in the WebSocket service.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Set operation of this property is available before the WebSocket connection has been /// Set operation of this property is available before the WebSocket connection has been
@ -228,9 +226,7 @@ namespace WebSocketSharp.Server
/// </value> /// </value>
public string Protocol { public string Protocol {
get { get {
return _websocket != null return _websocket != null ? _websocket.Protocol : (_protocol ?? String.Empty);
? _websocket.Protocol
: _protocol ?? String.Empty;
} }
set { set {
@ -245,30 +241,28 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Gets the time that the current session has started. /// Gets the time that a session has started.
/// </summary> /// </summary>
/// <value> /// <value>
/// A <see cref="DateTime"/> that represents the time that the current session has started, /// A <see cref="DateTime"/> that represents the time that the session has started,
/// or <see cref="DateTime.MaxValue"/> if the WebSocket connection isn't established. /// or <see cref="DateTime.MaxValue"/> if the WebSocket connection isn't established.
/// </value> /// </value>
public DateTime StartTime { public DateTime StartTime {
get { get {
return _start; return _startTime;
} }
} }
/// <summary> /// <summary>
/// Gets the state of the <see cref="WebSocket"/> used in the current session. /// Gets the state of the <see cref="WebSocket"/> used in a session.
/// </summary> /// </summary>
/// <value> /// <value>
/// One of the <see cref="WebSocketState"/> enum values, indicates the state of /// One of the <see cref="WebSocketState"/> enum values, indicates the state of
/// the <see cref="WebSocket"/> used in the current session. /// the <see cref="WebSocket"/> used in the session.
/// </value> /// </value>
public WebSocketState State { public WebSocketState State {
get { get {
return _websocket != null return _websocket != null ? _websocket.ReadyState : WebSocketState.Connecting;
? _websocket.ReadyState
: WebSocketState.Connecting;
} }
} }
@ -313,7 +307,7 @@ namespace WebSocketSharp.Server
return; return;
} }
_start = DateTime.Now; _startTime = DateTime.Now;
OnOpen (); OnOpen ();
} }
@ -375,7 +369,7 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Called when the WebSocket connection used in the current session has been closed. /// Called when the WebSocket connection used in a session has been closed.
/// </summary> /// </summary>
/// <param name="e"> /// <param name="e">
/// A <see cref="CloseEventArgs"/> that represents the event data passed to /// A <see cref="CloseEventArgs"/> that represents the event data passed to
@ -386,7 +380,7 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Called when the <see cref="WebSocket"/> used in the current session gets an error. /// Called when the <see cref="WebSocket"/> used in a session gets an error.
/// </summary> /// </summary>
/// <param name="e"> /// <param name="e">
/// A <see cref="ErrorEventArgs"/> that represents the event data passed to /// A <see cref="ErrorEventArgs"/> that represents the event data passed to
@ -397,7 +391,7 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Called when the <see cref="WebSocket"/> used in the current session receives a message. /// Called when the <see cref="WebSocket"/> used in a session receives a message.
/// </summary> /// </summary>
/// <param name="e"> /// <param name="e">
/// A <see cref="MessageEventArgs"/> that represents the event data passed to /// A <see cref="MessageEventArgs"/> that represents the event data passed to
@ -408,14 +402,14 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Called when the WebSocket connection used in the current session has been established. /// Called when the WebSocket connection used in a session has been established.
/// </summary> /// </summary>
protected virtual void OnOpen () protected virtual void OnOpen ()
{ {
} }
/// <summary> /// <summary>
/// Sends a binary <paramref name="data"/> to the client on the current session. /// Sends a binary <paramref name="data"/> to the client on a session.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This method is available after the WebSocket connection has been established. /// This method is available after the WebSocket connection has been established.
@ -430,8 +424,7 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Sends the specified <paramref name="file"/> as a binary data to the client /// Sends the specified <paramref name="file"/> as a binary data to the client on a session.
/// on the current session.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This method is available after the WebSocket connection has been established. /// This method is available after the WebSocket connection has been established.
@ -446,7 +439,7 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Sends a text <paramref name="data"/> to the client on the current session. /// Sends a text <paramref name="data"/> to the client on a session.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This method is available after the WebSocket connection has been established. /// This method is available after the WebSocket connection has been established.
@ -461,7 +454,7 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Sends a binary <paramref name="data"/> asynchronously to the client on the current session. /// Sends a binary <paramref name="data"/> asynchronously to the client on a session.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>
@ -487,7 +480,7 @@ namespace WebSocketSharp.Server
/// <summary> /// <summary>
/// Sends the specified <paramref name="file"/> as a binary data asynchronously /// Sends the specified <paramref name="file"/> as a binary data asynchronously
/// to the client on the current session. /// to the client on a session.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>
@ -512,7 +505,7 @@ namespace WebSocketSharp.Server
} }
/// <summary> /// <summary>
/// Sends a text <paramref name="data"/> asynchronously to the client on the current session. /// Sends a text <paramref name="data"/> asynchronously to the client on a session.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>
@ -538,7 +531,7 @@ namespace WebSocketSharp.Server
/// <summary> /// <summary>
/// Sends a binary data from the specified <see cref="Stream"/> asynchronously /// Sends a binary data from the specified <see cref="Stream"/> asynchronously
/// to the client on the current session. /// to the client on a session.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>