diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 7ecb912c..dcd82a66 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -234,7 +234,7 @@ namespace WebSocketSharp : null; } - internal static string CheckIfStopped (this ServerState state) + internal static string CheckIfStartable (this ServerState state) { return state == ServerState.START ? "The server has already started." diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index 99d99b17..77ef3229 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -74,20 +74,33 @@ namespace WebSocketSharp.Server #region Public Constructors /// - /// Initializes a new instance of the class that - /// listens for incoming requests on port 80. + /// Initializes a new instance of the class. /// + /// + /// An instance initialized by this constructor listens for the incoming + /// requests on port 80. + /// public HttpServer () : this (80) { } /// - /// Initializes a new instance of the class that - /// listens for incoming requests on the specified . + /// Initializes a new instance of the class with + /// the specified . /// + /// + /// + /// An instance initialized by this constructor listens for the incoming + /// requests on . + /// + /// + /// And if is 443, that instance provides a secure + /// connection. + /// + /// /// - /// An that contains a port number. + /// An that represents the port number to listen. /// /// /// is not between 1 and 65535. @@ -98,12 +111,15 @@ namespace WebSocketSharp.Server } /// - /// Initializes a new instance of the class that - /// listens for incoming requests on the specified - /// and . + /// Initializes a new instance of the class with + /// the specified and . /// + /// + /// An instance initialized by this constructor listens for the incoming + /// requests on . + /// /// - /// An that contains a port number. + /// An that represents the port number to listen. /// /// /// A that indicates providing a secure connection or not. @@ -150,8 +166,8 @@ namespace WebSocketSharp.Server /// Gets or sets the scheme used to authenticate the clients. /// /// - /// One of the values - /// that indicates the scheme used to authenticate the clients. The default + /// One of the enum + /// values, indicates the scheme used to authenticate the clients. The default /// value is . /// public AuthenticationSchemes AuthenticationSchemes { @@ -238,9 +254,9 @@ namespace WebSocketSharp.Server /// Gets the logging functions. /// /// - /// The default logging level is the . If you - /// change the current logging level, you set the Log.Level property - /// to any of the values. + /// The default logging level is . If you would + /// like to change it, you should set the Log.Level property to any of + /// the enum values. /// /// /// A that provides the logging functions. @@ -255,7 +271,7 @@ namespace WebSocketSharp.Server /// Gets the port on which to listen for incoming requests. /// /// - /// An that contains a port number. + /// An that represents the port number to listen. /// public int Port { get { @@ -268,7 +284,7 @@ namespace WebSocketSharp.Server /// . /// /// - /// A that contains the name of the realm. + /// A that represents the name of the realm. /// The default value is SECRET AREA. /// public string Realm { @@ -288,7 +304,7 @@ namespace WebSocketSharp.Server /// Gets or sets the document root path of server. /// /// - /// A that contains the document root path of server. + /// A that represents the document root path of server. /// The default value is ./Public. /// public string RootPath { @@ -312,8 +328,8 @@ namespace WebSocketSharp.Server /// /// /// A Func<, > - /// delegate that references the method(s) used to find the credentials. The - /// default value is a function that only returns . + /// delegate that references the method(s) used to find the credentials. + /// The default value is a function that only returns . /// public Func UserCredentialsFinder { get { @@ -329,7 +345,7 @@ namespace WebSocketSharp.Server } /// - /// Gets the functions for the WebSocket services provided by the + /// Gets the access to the WebSocket services provided by the /// . /// /// @@ -535,11 +551,6 @@ namespace WebSocketSharp.Server return true; } - private string checkIfCanStop (Func checkParams) - { - return _state.CheckIfStart () ?? checkParams (); - } - private string checkIfCertExists () { return _secure && @@ -598,7 +609,7 @@ namespace WebSocketSharp.Server /// and removes '/' from tail end of . /// /// - /// A that contains an absolute path to the WebSocket + /// A that represents the absolute path to the WebSocket /// service. /// /// @@ -628,7 +639,7 @@ namespace WebSocketSharp.Server /// /// /// - /// A that contains an absolute path to the WebSocket + /// A that represents the absolute path to the WebSocket /// service. /// /// @@ -639,7 +650,8 @@ namespace WebSocketSharp.Server /// The type of the WebSocket service. The T must inherit the /// class. /// - public void AddWebSocketService (string servicePath, Func serviceConstructor) + public void AddWebSocketService ( + string servicePath, Func serviceConstructor) where T : WebSocketService { var msg = servicePath.CheckIfValidServicePath () ?? @@ -667,13 +679,14 @@ namespace WebSocketSharp.Server /// Gets the contents of the file with the specified . /// /// - /// An array of that contains the contents of the file if + /// An array of that receives the contents of the file if /// it exists; otherwise, . /// /// - /// A that contains a virtual path to the file to get. + /// A that represents the virtual path to the file + /// to get. /// - public byte[] GetFile (string path) + public byte [] GetFile (string path) { var filePath = RootPath + path; if (_windows) @@ -685,8 +698,7 @@ namespace WebSocketSharp.Server } /// - /// Removes the WebSocket service with the specified - /// . + /// Removes the WebSocket service with the specified . /// /// /// This method converts to URL-decoded string @@ -697,7 +709,7 @@ namespace WebSocketSharp.Server /// otherwise, false. /// /// - /// A that contains an absolute path to the WebSocket + /// A that represents the absolute path to the WebSocket /// service to find. /// public bool RemoveWebSocketService (string servicePath) @@ -719,7 +731,7 @@ namespace WebSocketSharp.Server public void Start () { lock (_sync) { - var msg = _state.CheckIfStopped () ?? checkIfCertExists (); + var msg = _state.CheckIfStartable () ?? checkIfCertExists (); if (msg != null) { _logger.Error ( String.Format ( @@ -772,9 +784,9 @@ namespace WebSocketSharp.Server { byte [] data = null; lock (_sync) { - var msg = checkIfCanStop ( - () => code.CheckIfValidCloseStatusCode () ?? - (data = code.Append (reason)).CheckIfValidControlData ("reason")); + var msg = _state.CheckIfStart () ?? + code.CheckIfValidCloseStatusCode () ?? + (data = code.Append (reason)).CheckIfValidControlData ("reason"); if (msg != null) { _logger.Error ( @@ -808,9 +820,8 @@ namespace WebSocketSharp.Server { byte [] data = null; lock (_sync) { - var msg = checkIfCanStop ( - () => (data = ((ushort) code).Append (reason)) - .CheckIfValidControlData ("reason")); + var msg = _state.CheckIfStart () ?? + (data = ((ushort) code).Append (reason)).CheckIfValidControlData ("reason"); if (msg != null) { _logger.Error ( diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index 8b127d64..f593576d 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -48,8 +48,7 @@ using WebSocketSharp.Net.WebSockets; namespace WebSocketSharp.Server { /// - /// Provides the functions of the server that receives the WebSocket connection - /// requests. + /// Provides a WebSocket protocol server. /// /// /// The WebSocketServer class provides the multi WebSocket service. @@ -78,9 +77,12 @@ namespace WebSocketSharp.Server #region Public Constructors /// - /// Initializes a new instance of the class - /// that listens for incoming requests on port 80. + /// Initializes a new instance of the class. /// + /// + /// An instance initialized by this constructor listens for the incoming + /// connection requests on port 80. + /// public WebSocketServer () : this (80) { @@ -88,11 +90,20 @@ namespace WebSocketSharp.Server /// /// Initializes a new instance of the class - /// that listens for incoming connection attempts on the specified - /// . + /// with the specified . /// + /// + /// + /// An instance initialized by this constructor listens for the incoming + /// connection requests on . + /// + /// + /// And if is 443, that instance provides a secure + /// connection. + /// + /// /// - /// An that contains a port number. + /// An that represents the port number to listen. /// /// /// is not between 1 and 65535. @@ -104,11 +115,14 @@ namespace WebSocketSharp.Server /// /// Initializes a new instance of the class - /// that listens for incoming connection attempts on the specified WebSocket - /// URL. + /// with the specified WebSocket URL. /// + /// + /// An instance initialized by this constructor listens for the incoming + /// connection requests on the port number of . + /// /// - /// A that contains a WebSocket URL. + /// A that represents the WebSocket URL of the server. /// /// /// is . @@ -140,11 +154,14 @@ namespace WebSocketSharp.Server /// /// Initializes a new instance of the class - /// that listens for incoming connection attempts on the specified - /// and . + /// with the specified and . /// + /// + /// An instance initialized by this constructor listens for the incoming + /// connection requests on . + /// /// - /// An that contains a port number. + /// An that represents the port number to listen. /// /// /// A that indicates providing a secure connection or not. @@ -163,15 +180,23 @@ namespace WebSocketSharp.Server /// /// Initializes a new instance of the class - /// that listens for incoming connection attempts on the specified - /// and . + /// with the specified and . /// + /// + /// + /// An instance initialized by this constructor listens for the incoming + /// connection requests on . + /// + /// + /// And if is 443, that instance provides a secure + /// connection. + /// + /// /// - /// A that represents the local IP - /// address. + /// A that represents the local IP address. /// /// - /// An that contains a port number. + /// An that represents the port number to listen. /// /// /// is . @@ -189,16 +214,18 @@ namespace WebSocketSharp.Server /// /// Initializes a new instance of the class - /// that listens for incoming connection attempts on the specified - /// , and - /// . + /// with the specified , , + /// and . /// + /// + /// An instance initialized by this constructor listens for the incoming + /// connection requests on . + /// /// - /// A that represents the local IP - /// address. + /// A that represents the local IP address. /// /// - /// An that contains a port number. + /// An that represents the port number to listen. /// /// /// A that indicates providing a secure connection or not. @@ -251,12 +278,11 @@ namespace WebSocketSharp.Server #region Public Properties /// - /// Gets the local IP address on which to listen for incoming connection - /// attempts. + /// Gets the local IP address of the server. /// /// /// A that represents the local IP - /// address. + /// address of the server. /// public System.Net.IPAddress Address { get { @@ -268,8 +294,8 @@ namespace WebSocketSharp.Server /// Gets or sets the scheme used to authenticate the clients. /// /// - /// One of the values - /// that indicates the scheme used to authenticate the clients. The default + /// One of the enum + /// values, indicates the scheme used to authenticate the clients. The default /// value is . /// public AuthenticationSchemes AuthenticationSchemes { @@ -352,9 +378,9 @@ namespace WebSocketSharp.Server /// Gets the logging functions. /// /// - /// The default logging level is the . If you - /// change the current logging level, you set the Log.Level property - /// to any of the values. + /// The default logging level is . If you would + /// like to change it, you should set the Log.Level property to any of + /// the enum values. /// /// /// A that provides the logging functions. @@ -366,10 +392,10 @@ namespace WebSocketSharp.Server } /// - /// Gets the port on which to listen for incoming connection attempts. + /// Gets the port on which to listen for incoming connection requests. /// /// - /// An that contains a port number. + /// An that represents the port number to listen. /// public int Port { get { @@ -382,7 +408,7 @@ namespace WebSocketSharp.Server /// . /// /// - /// A that contains the name of the realm. + /// A that represents the name of the realm. /// The default value is SECRET AREA. /// public string Realm { @@ -404,8 +430,8 @@ namespace WebSocketSharp.Server /// /// /// A Func<, > - /// delegate that references the method(s) used to find the credentials. The - /// default value is a function that only returns . + /// delegate that references the method(s) used to find the credentials. + /// The default value is a function that only returns . /// public Func UserCredentialsFinder { get { @@ -421,7 +447,7 @@ namespace WebSocketSharp.Server } /// - /// Gets the functions for the WebSocket services provided by the + /// Gets the access to the WebSocket services provided by the /// . /// /// @@ -549,11 +575,6 @@ namespace WebSocketSharp.Server return true; } - private string checkIfCanStop (Func checkParams) - { - return _state.CheckIfStart () ?? checkParams (); - } - private string checkIfCertExists () { return _secure && _cert == null @@ -635,7 +656,7 @@ namespace WebSocketSharp.Server /// and removes '/' from tail end of . /// /// - /// A that contains an absolute path to the WebSocket + /// A that represents the absolute path to the WebSocket /// service. /// /// @@ -665,7 +686,7 @@ namespace WebSocketSharp.Server /// /// /// - /// A that contains an absolute path to the WebSocket + /// A that represents the absolute path to the WebSocket /// service. /// /// @@ -676,7 +697,8 @@ namespace WebSocketSharp.Server /// The type of the WebSocket service. The T must inherit the /// class. /// - public void AddWebSocketService (string servicePath, Func serviceConstructor) + public void AddWebSocketService ( + string servicePath, Func serviceConstructor) where T : WebSocketService { var msg = servicePath.CheckIfValidServicePath () ?? @@ -713,7 +735,7 @@ namespace WebSocketSharp.Server /// otherwise, false. /// /// - /// A that contains an absolute path to the WebSocket + /// A that represents the absolute path to the WebSocket /// service to find. /// public bool RemoveWebSocketService (string servicePath) @@ -735,7 +757,7 @@ namespace WebSocketSharp.Server public void Start () { lock (_sync) { - var msg = _state.CheckIfStopped () ?? checkIfCertExists (); + var msg = _state.CheckIfStartable () ?? checkIfCertExists (); if (msg != null) { _logger.Error ( String.Format ( @@ -788,9 +810,9 @@ namespace WebSocketSharp.Server { byte [] data = null; lock (_sync) { - var msg = checkIfCanStop ( - () => code.CheckIfValidCloseStatusCode () ?? - (data = code.Append (reason)).CheckIfValidControlData ("reason")); + var msg = _state.CheckIfStart () ?? + code.CheckIfValidCloseStatusCode () ?? + (data = code.Append (reason)).CheckIfValidControlData ("reason"); if (msg != null) { _logger.Error ( @@ -824,9 +846,8 @@ namespace WebSocketSharp.Server { byte [] data = null; lock (_sync) { - var msg = checkIfCanStop ( - () => (data = ((ushort) code).Append (reason)) - .CheckIfValidControlData ("reason")); + var msg = _state.CheckIfStart () ?? + (data = ((ushort) code).Append (reason)).CheckIfValidControlData ("reason"); if (msg != null) { _logger.Error (