diff --git a/websocket-sharp/Server/WebSocketServiceHostManager.cs b/websocket-sharp/Server/WebSocketServiceHostManager.cs index 8c21eac6..6e4c055d 100644 --- a/websocket-sharp/Server/WebSocketServiceHostManager.cs +++ b/websocket-sharp/Server/WebSocketServiceHostManager.cs @@ -134,7 +134,7 @@ namespace WebSocketSharp.Server } /// - /// Gets the collection of the WebSocket service hosts managed by the server. + /// Gets the collection of the WebSocket service hosts managed by the manager. /// /// /// An IEnumerable<WebSocketServiceHost> that contains the collection of @@ -165,11 +165,11 @@ namespace WebSocketSharp.Server } /// - /// Gets the number of the sessions to the every WebSocket service provided by - /// the server. + /// Gets the number of the WebSocket sessions to the server. /// /// - /// An that represents the session count of the server. + /// An that represents the number of the sessions to the + /// server. /// public int SessionCount { get { @@ -509,18 +509,13 @@ namespace WebSocketSharp.Server else broadcast (Opcode.BINARY, new MemoryStream (data), completed); }, - ex => { - _logger.Fatal (ex.ToString ()); - }); + ex => _logger.Fatal (ex.ToString ())); } /// /// Broadcasts a binary to all clients of the /// WebSocket service with the specified . /// - /// - /// This method doesn't wait for the broadcast to be complete. - /// /// /// A that represents the absolute path to the WebSocket /// service to find. @@ -530,16 +525,15 @@ namespace WebSocketSharp.Server /// public void BroadcastTo (string servicePath, byte [] data) { - BroadcastTo (servicePath, data, null); + WebSocketServiceHost host; + if (TryGetServiceHost (servicePath, out host)) + host.Sessions.Broadcast (data); } /// /// Broadcasts a text to all clients of the WebSocket /// service with the specified . /// - /// - /// This method doesn't wait for the broadcast to be complete. - /// /// /// A that represents the absolute path to the WebSocket /// service to find. @@ -549,12 +543,14 @@ namespace WebSocketSharp.Server /// public void BroadcastTo (string servicePath, string data) { - BroadcastTo (servicePath, data, null); + WebSocketServiceHost host; + if (TryGetServiceHost (servicePath, out host)) + host.Sessions.Broadcast (data); } /// - /// Broadcasts a binary to all clients of the - /// WebSocket service with the specified . + /// Broadcasts a binary asynchronously to all clients + /// of the WebSocket service with the specified . /// /// /// This method doesn't wait for the broadcast to be complete. @@ -570,16 +566,17 @@ namespace WebSocketSharp.Server /// A delegate that references the method(s) called when /// the broadcast is complete. /// - public void BroadcastTo (string servicePath, byte [] data, Action completed) + public void BroadcastToAsync ( + string servicePath, byte [] data, Action completed) { WebSocketServiceHost host; if (TryGetServiceHost (servicePath, out host)) - host.Sessions.Broadcast (data, completed); + host.Sessions.BroadcastAsync (data, completed); } /// - /// Broadcasts a text to all clients of the WebSocket - /// service with the specified . + /// Broadcasts a text asynchronously to all clients of + /// the WebSocket service with the specified . /// /// /// This method doesn't wait for the broadcast to be complete. @@ -595,16 +592,18 @@ namespace WebSocketSharp.Server /// A delegate that references the method(s) called when /// the broadcast is complete. /// - public void BroadcastTo (string servicePath, string data, Action completed) + public void BroadcastToAsync ( + string servicePath, string data, Action completed) { WebSocketServiceHost host; if (TryGetServiceHost (servicePath, out host)) - host.Sessions.Broadcast (data, completed); + host.Sessions.BroadcastAsync (data, completed); } /// - /// Broadcasts a binary data from the specified to all - /// clients of the WebSocket service with the specified . + /// Broadcasts a binary data from the specified + /// asynchronously to all clients of the WebSocket service with the specified + /// . /// /// /// This method doesn't wait for the broadcast to be complete. @@ -624,12 +623,12 @@ namespace WebSocketSharp.Server /// A delegate that references the method(s) called when /// the broadcast is complete. /// - public void BroadcastTo ( + public void BroadcastToAsync ( string servicePath, Stream stream, int length, Action completed) { WebSocketServiceHost host; if (TryGetServiceHost (servicePath, out host)) - host.Sessions.Broadcast (stream, length, completed); + host.Sessions.BroadcastAsync (stream, length, completed); } /// @@ -741,7 +740,7 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID to find. + /// A that represents the ID of the session to close. /// public void CloseSession (string servicePath, string id) { @@ -759,10 +758,10 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID to find. + /// A that represents the ID of the session to close. /// /// - /// A that indicates the status code for closure. + /// A that represents the status code for closure. /// /// /// A that represents the reason for closure. @@ -784,7 +783,7 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID to find. + /// A that represents the ID of the session to close. /// /// /// One of the values that indicate the status @@ -814,8 +813,8 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID that represents the - /// destination for the Ping. + /// A that represents the ID of the session to send the + /// Ping to. /// public bool PingTo (string servicePath, string id) { @@ -838,8 +837,8 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID that represents the - /// destination for the Ping. + /// A that represents the ID of the session to send the + /// Ping to. /// /// /// A that represents the message to send. @@ -860,8 +859,8 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// An array of that contains the binary data to send. @@ -882,8 +881,8 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// A that represents the text data to send. @@ -908,8 +907,8 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// An array of that contains the binary data to send. @@ -941,8 +940,8 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// A that represents the text data to send. @@ -974,8 +973,8 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// A object from which contains the binary data to send. diff --git a/websocket-sharp/Server/WebSocketSessionManager.cs b/websocket-sharp/Server/WebSocketSessionManager.cs index d4dcbb95..f5655cdb 100644 --- a/websocket-sharp/Server/WebSocketSessionManager.cs +++ b/websocket-sharp/Server/WebSocketSessionManager.cs @@ -104,10 +104,12 @@ namespace WebSocketSharp.Server #region Public Properties /// - /// Gets the collection of every ID of the active sessions to the Websocket service. + /// Gets the collection of every ID of the active sessions to the Websocket + /// service. /// /// - /// An IEnumerable<string> that contains the collection of every ID of the active sessions. + /// An IEnumerable<string> that contains the collection of every ID of + /// the active sessions. /// public IEnumerable ActiveIDs { get { @@ -121,12 +123,11 @@ namespace WebSocketSharp.Server /// Gets the number of the sessions to the Websocket service. /// /// - /// An that contains the number of the sessions. + /// An that represents the number of the sessions. /// public int Count { get { - lock (_sync) - { + lock (_sync) { return _sessions.Count; } } @@ -136,22 +137,24 @@ namespace WebSocketSharp.Server /// Gets the collection of every ID of the sessions to the Websocket service. /// /// - /// An IEnumerable<string> that contains the collection of every ID of the sessions. + /// An IEnumerable<string> that contains the collection of every ID of + /// the sessions. /// public IEnumerable IDs { get { - lock (_sync) - { + lock (_sync) { return _sessions.Keys.ToList (); } } } /// - /// Gets the collection of every ID of the inactive sessions to the Websocket service. + /// Gets the collection of every ID of the inactive sessions to the Websocket + /// service. /// /// - /// An IEnumerable<string> that contains the collection of every ID of the inactive sessions. + /// An IEnumerable<string> that contains the collection of every ID of + /// the inactive sessions. /// public IEnumerable InactiveIDs { get { @@ -165,11 +168,12 @@ namespace WebSocketSharp.Server /// Gets a WebSocket session information with the specified . /// /// - /// A instance that contains the session information - /// if the session is successfully found; otherwise, . + /// A instance that represents the session if + /// it's successfully found; otherwise, . /// /// - /// A that contains an ID of the session to find. + /// A that represents the ID of the WebSocket session to + /// get. /// public IWebSocketSession this [string id] { get { @@ -181,11 +185,12 @@ namespace WebSocketSharp.Server } /// - /// Gets a value indicating whether the manager cleans up the inactive sessions periodically. + /// Gets a value indicating whether the manager cleans up the inactive + /// sessions periodically. /// /// - /// true if the manager cleans up the inactive sessions every 60 seconds; - /// otherwise, false. + /// true if the manager cleans up the inactive sessions every 60 + /// seconds; otherwise, false. /// public bool KeepClean { get { @@ -206,15 +211,15 @@ namespace WebSocketSharp.Server /// Gets the collection of the session informations to the Websocket service. /// /// - /// An IEnumerable<IWebSocketSession> that contains the collection of the session informations. + /// An IEnumerable<IWebSocketSession> that contains the collection of + /// the session informations to the Websocket service. /// public IEnumerable Sessions { get { if (_state == ServerState.SHUTDOWN) return _emptySessions; - lock (_sync) - { + lock (_sync) { return _sessions.Values.ToList (); } } @@ -224,53 +229,7 @@ namespace WebSocketSharp.Server #region Private Methods - private static string createID () - { - return Guid.NewGuid ().ToString ("N"); - } - - private void setSweepTimer (double interval) - { - _sweepTimer = new System.Timers.Timer (interval); - _sweepTimer.Elapsed += (sender, e) => - { - Sweep (); - }; - } - - private bool tryGetSession (string id, out IWebSocketSession session) - { - bool result; - lock (_sync) - { - result = _sessions.TryGetValue (id, out session); - } - - if (!result) - _logger.Error ("A WebSocket session with the specified ID not found.\nID: " + id); - - return result; - } - - #endregion - - #region Internal Methods - - internal string Add (IWebSocketSession session) - { - lock (_sync) - { - if (_state != ServerState.START) - return null; - - var id = createID (); - _sessions.Add (id, session); - - return id; - } - } - - internal void Broadcast (Opcode opcode, byte [] data, Action completed) + private void broadcast (Opcode opcode, byte [] data, Action completed) { var cache = new Dictionary (); try { @@ -286,7 +245,7 @@ namespace WebSocketSharp.Server } } - internal void Broadcast (Opcode opcode, Stream stream, Action completed) + private void broadcast (Opcode opcode, Stream stream, Action completed) { var cache = new Dictionary (); try { @@ -305,11 +264,64 @@ namespace WebSocketSharp.Server } } + private void broadcastAsync (Opcode opcode, byte [] data, Action completed) + { + ThreadPool.QueueUserWorkItem ( + state => broadcast (opcode, data, completed)); + } + + private void broadcastAsync (Opcode opcode, Stream stream, Action completed) + { + ThreadPool.QueueUserWorkItem ( + state => broadcast (opcode, stream, completed)); + } + + private static string createID () + { + return Guid.NewGuid ().ToString ("N"); + } + + private void setSweepTimer (double interval) + { + _sweepTimer = new System.Timers.Timer (interval); + _sweepTimer.Elapsed += (sender, e) => Sweep (); + } + + private bool tryGetSession (string id, out IWebSocketSession session) + { + bool result; + lock (_sync) { + result = _sessions.TryGetValue (id, out session); + } + + if (!result) + _logger.Error ( + "A WebSocket session with the specified ID not found.\nID: " + id); + + return result; + } + + #endregion + + #region Internal Methods + + internal string Add (IWebSocketSession session) + { + lock (_sync) { + if (_state != ServerState.START) + return null; + + var id = createID (); + _sessions.Add (id, session); + + return id; + } + } + internal void Broadcast ( Opcode opcode, byte [] data, Dictionary cache) { - foreach (var session in Sessions) - { + foreach (var session in Sessions) { if (_state != ServerState.START) break; @@ -320,8 +332,7 @@ namespace WebSocketSharp.Server internal void Broadcast ( Opcode opcode, Stream stream, Dictionary cache) { - foreach (var session in Sessions) - { + foreach (var session in Sessions) { if (_state != ServerState.START) break; @@ -329,35 +340,16 @@ namespace WebSocketSharp.Server } } - internal void BroadcastAsync (Opcode opcode, byte [] data, Action completed) - { - WaitCallback callback = state => - { - Broadcast (opcode, data, completed); - }; - - ThreadPool.QueueUserWorkItem (callback); - } - - internal void BroadcastAsync (Opcode opcode, Stream stream, Action completed) - { - WaitCallback callback = state => - { - Broadcast (opcode, stream, completed); - }; - - ThreadPool.QueueUserWorkItem (callback); - } - - internal Dictionary Broadping (byte [] frameAsBytes, int timeOut) + internal Dictionary Broadping ( + byte [] frameAsBytes, int timeOut) { var result = new Dictionary (); - foreach (var session in Sessions) - { + foreach (var session in Sessions) { if (_state != ServerState.START) break; - result.Add (session.ID, session.Context.WebSocket.Ping (frameAsBytes, timeOut)); + result.Add ( + session.ID, session.Context.WebSocket.Ping (frameAsBytes, timeOut)); } return result; @@ -365,8 +357,7 @@ namespace WebSocketSharp.Server internal bool Remove (string id) { - lock (_sync) - { + lock (_sync) { return _sessions.Remove (id); } } @@ -381,17 +372,17 @@ namespace WebSocketSharp.Server { var payload = new PayloadData (data); var args = new CloseEventArgs (payload); - var frameAsBytes = send - ? WsFrame.CreateCloseFrame (Mask.UNMASK, payload).ToByteArray () - : null; + var frameAsBytes = + send + ? WsFrame.CreateCloseFrame (Mask.UNMASK, payload).ToByteArray () + : null; Stop (args, frameAsBytes); } internal void Stop (CloseEventArgs args, byte [] frameAsBytes) { - lock (_sync) - { + lock (_sync) { _state = ServerState.SHUTDOWN; _sweepTimer.Enabled = false; @@ -407,177 +398,170 @@ namespace WebSocketSharp.Server #region Public Methods /// - /// Broadcasts a binary to all clients of a WebSocket service. + /// Broadcasts a binary to all clients of the + /// WebSocket service. /// - /// - /// This method does not wait for the broadcast to be complete. - /// /// - /// An array of that contains a binary data to broadcast. + /// An array of that contains the binary data to broadcast. /// public void Broadcast (byte [] data) - { - Broadcast (data, null); - } - - /// - /// Broadcasts a text to all clients of a WebSocket service. - /// - /// - /// This method does not wait for the broadcast to be complete. - /// - /// - /// A that contains a text data to broadcast. - /// - public void Broadcast (string data) - { - Broadcast (data, null); - } - - /// - /// Broadcasts a binary to all clients of a WebSocket service. - /// - /// - /// This method does not wait for the broadcast to be complete. - /// - /// - /// An array of that contains a binary data to broadcast. - /// - /// - /// A delegate that references the method(s) called when - /// the broadcast is complete. - /// - public void Broadcast (byte [] data, Action completed) { var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); - if (msg != null) - { + if (msg != null) { _logger.Error (msg); return; } if (data.LongLength <= WebSocket.FragmentLength) - BroadcastAsync (Opcode.BINARY, data, completed); + broadcast (Opcode.BINARY, data, null); else - BroadcastAsync (Opcode.BINARY, new MemoryStream (data), completed); + broadcast (Opcode.BINARY, new MemoryStream (data), null); } /// - /// Broadcasts a text to all clients of a WebSocket service. + /// Broadcasts a text to all clients of the WebSocket + /// service. /// - /// - /// This method does not wait for the broadcast to be complete. - /// /// - /// A that contains a text data to broadcast. + /// A that represents the text data to broadcast. /// - /// - /// A delegate that references the method(s) called when - /// the broadcast is complete. - /// - public void Broadcast (string data, Action completed) + public void Broadcast (string data) { var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); - if (msg != null) - { + if (msg != null) { _logger.Error (msg); return; } var rawData = Encoding.UTF8.GetBytes (data); if (rawData.LongLength <= WebSocket.FragmentLength) - BroadcastAsync (Opcode.TEXT, rawData, completed); + broadcast (Opcode.TEXT, rawData, null); else - BroadcastAsync (Opcode.TEXT, new MemoryStream (rawData), completed); + broadcast (Opcode.TEXT, new MemoryStream (rawData), null); } /// - /// Broadcasts a binary data from the specified - /// to all clients of a WebSocket service. + /// Broadcasts a binary asynchronously to all clients + /// of the WebSocket service. /// /// - /// This method does not wait for the broadcast to be complete. + /// This method doesn't wait for the broadcast to be complete. /// - /// - /// A object from which contains a binary data to broadcast. - /// - /// - /// An that contains the number of bytes to broadcast. - /// - public void Broadcast (Stream stream, int length) - { - Broadcast (stream, length, null); - } - - /// - /// Broadcasts a binary data from the specified - /// to all clients of a WebSocket service. - /// - /// - /// This method does not wait for the broadcast to be complete. - /// - /// - /// A object from which contains a binary data to broadcast. - /// - /// - /// An that contains the number of bytes to broadcast. + /// + /// An array of that contains the binary data to broadcast. /// /// /// A delegate that references the method(s) called when /// the broadcast is complete. /// - public void Broadcast (Stream stream, int length, Action completed) + public void BroadcastAsync (byte [] data, Action completed) + { + var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + if (msg != null) { + _logger.Error (msg); + return; + } + + if (data.LongLength <= WebSocket.FragmentLength) + broadcastAsync (Opcode.BINARY, data, completed); + else + broadcastAsync (Opcode.BINARY, new MemoryStream (data), completed); + } + + /// + /// Broadcasts a text asynchronously to all clients of + /// the WebSocket service. + /// + /// + /// This method doesn't wait for the broadcast to be complete. + /// + /// + /// A that represents the text data to broadcast. + /// + /// + /// A delegate that references the method(s) called when + /// the broadcast is complete. + /// + public void BroadcastAsync (string data, Action completed) + { + var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + if (msg != null) { + _logger.Error (msg); + return; + } + + var rawData = Encoding.UTF8.GetBytes (data); + if (rawData.LongLength <= WebSocket.FragmentLength) + broadcastAsync (Opcode.TEXT, rawData, completed); + else + broadcastAsync (Opcode.TEXT, new MemoryStream (rawData), completed); + } + + /// + /// Broadcasts a binary data from the specified + /// asynchronously to all clients of the WebSocket service. + /// + /// + /// This method doesn't wait for the broadcast to be complete. + /// + /// + /// A object from which contains the binary data to + /// broadcast. + /// + /// + /// An that represents the number of bytes to broadcast. + /// + /// + /// A delegate that references the method(s) called when + /// the broadcast is complete. + /// + public void BroadcastAsync (Stream stream, int length, Action completed) { var msg = _state.CheckIfStarted () ?? stream.CheckIfCanRead () ?? (length < 1 ? "'length' must be greater than 0." : null); - if (msg != null) - { + if (msg != null) { _logger.Error (msg); return; } stream.ReadBytesAsync ( length, - data => - { + data => { var len = data.Length; - if (len == 0) - { + if (len == 0) { _logger.Error ("A data cannot be read from 'stream'."); return; } if (len < length) - _logger.Warn (String.Format ( - "A data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}", - length, - len)); + _logger.Warn ( + String.Format ( + "A data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}", + length, + len)); if (len <= WebSocket.FragmentLength) - Broadcast (Opcode.BINARY, data, completed); + broadcast (Opcode.BINARY, data, completed); else - Broadcast (Opcode.BINARY, new MemoryStream (data), completed); + broadcast (Opcode.BINARY, new MemoryStream (data), completed); }, - ex => - { - _logger.Fatal (ex.ToString ()); - }); + ex => _logger.Fatal (ex.ToString ())); } /// - /// Sends Pings to all clients of a WebSocket service. + /// Sends Pings to all clients of the WebSocket service. /// /// - /// A Dictionary<string, bool> that contains the collection of pairs of session ID and - /// value indicating whether the WebSocket service received a Pong from each client in a time. + /// A Dictionary<string, bool> that contains the collection of pairs of + /// session ID and value indicating whether the WebSocket service received a + /// Pong from each client in a time. /// public Dictionary Broadping () { var msg = _state.CheckIfStarted (); - if (msg != null) - { + if (msg != null) { _logger.Error (msg); return null; } @@ -587,14 +571,15 @@ namespace WebSocketSharp.Server /// /// Sends Pings with the specified to all clients - /// of a WebSocket service. + /// of the WebSocket service. /// /// - /// A Dictionary<string, bool> that contains the collection of pairs of session ID and - /// value indicating whether the WebSocket service received a Pong from each client in a time. + /// A Dictionary<string, bool> that contains the collection of pairs of + /// session ID and value indicating whether the WebSocket service received a + /// Pong from each client in a time. /// /// - /// A that contains a message to send. + /// A that represents the message to send. /// public Dictionary Broadping (string message) { @@ -605,20 +590,20 @@ namespace WebSocketSharp.Server var msg = _state.CheckIfStarted () ?? (data = Encoding.UTF8.GetBytes (message)).CheckIfValidPingData (); - if (msg != null) - { + if (msg != null) { _logger.Error (msg); return null; } - return Broadping (WsFrame.CreatePingFrame (Mask.UNMASK, data).ToByteArray (), 1000); + return Broadping ( + WsFrame.CreatePingFrame (Mask.UNMASK, data).ToByteArray (), 1000); } /// /// Closes the session with the specified . /// /// - /// A that contains a session ID to find. + /// A that represents the ID of the session to close. /// public void CloseSession (string id) { @@ -628,17 +613,17 @@ namespace WebSocketSharp.Server } /// - /// Closes the session with the specified , - /// and . + /// Closes the session with the specified , + /// and . /// /// - /// A that contains a session ID to find. + /// A that represents the ID of the session to close. /// /// - /// A that contains a status code indicating the reason for closure. + /// A that represents the status code for closure. /// /// - /// A that contains the reason for closure. + /// A that represents the reason for closure. /// public void CloseSession (string id, ushort code, string reason) { @@ -648,17 +633,18 @@ namespace WebSocketSharp.Server } /// - /// Closes the session with the specified , - /// and . + /// Closes the session with the specified , + /// and . /// /// - /// A that contains a session ID to find. + /// A that represents the ID of the session to close. /// /// - /// One of the values that indicate the status codes for closure. + /// One of the values that indicate the status + /// codes for closure. /// /// - /// A that contains the reason for closure. + /// A that represents the reason for closure. /// public void CloseSession (string id, CloseStatusCode code, string reason) { @@ -668,20 +654,22 @@ namespace WebSocketSharp.Server } /// - /// Sends a Ping to the client associated with the specified . + /// Sends a Ping to the client associated with the specified + /// . /// /// - /// true if the WebSocket service receives a Pong from the client in a time; - /// otherwise, false. + /// true if the WebSocket service receives a Pong from the client in a + /// time; otherwise, false. /// /// - /// A that contains a session ID that represents the destination - /// for the Ping. + /// A that represents the ID of the session to send the + /// Ping to. /// public bool PingTo (string id) { IWebSocketSession session; - return TryGetSession (id, out session) && session.Context.WebSocket.Ping (); + return TryGetSession (id, out session) && + session.Context.WebSocket.Ping (); } /// @@ -689,20 +677,21 @@ namespace WebSocketSharp.Server /// associated with the specified . /// /// - /// true if the WebSocket service receives a Pong from the client in a time; - /// otherwise, false. + /// true if the WebSocket service receives a Pong from the client in a + /// time; otherwise, false. /// /// - /// A that contains a session ID that represents the destination - /// for the Ping. + /// A that represents the ID of the session to send the + /// Ping to. /// /// - /// A that contains a message to send. + /// A that represents the message to send. /// public bool PingTo (string id, string message) { IWebSocketSession session; - return TryGetSession (id, out session) && session.Context.WebSocket.Ping (message); + return TryGetSession (id, out session) && + session.Context.WebSocket.Ping (message); } /// @@ -710,8 +699,8 @@ namespace WebSocketSharp.Server /// specified . /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// An array of that contains the binary data to send. @@ -728,8 +717,8 @@ namespace WebSocketSharp.Server /// specified . /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// A that represents the text data to send. @@ -749,8 +738,8 @@ namespace WebSocketSharp.Server /// This method doesn't wait for the send to be complete. /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// An array of that contains the binary data to send. @@ -776,8 +765,8 @@ namespace WebSocketSharp.Server /// This method doesn't wait for the send to be complete. /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// A that represents the text data to send. @@ -803,8 +792,8 @@ namespace WebSocketSharp.Server /// This method doesn't wait for the send to be complete. /// /// - /// A that represents the session ID that represents the - /// destination for the data. + /// A that represents the ID of the session to send the + /// data to. /// /// /// A object from which contains the binary data to send. @@ -834,19 +823,15 @@ namespace WebSocketSharp.Server if (_state != ServerState.START || _sweeping || Count == 0) return; - lock (_forSweep) - { + lock (_forSweep) { _sweeping = true; - foreach (var id in InactiveIDs) - { + foreach (var id in InactiveIDs) { if (_state != ServerState.START) break; - lock (_sync) - { + lock (_sync) { IWebSocketSession session; - if (_sessions.TryGetValue (id, out session)) - { + if (_sessions.TryGetValue (id, out session)) { var state = session.State; if (state == WebSocketState.OPEN) session.Context.WebSocket.Close (CloseStatusCode.ABNORMAL); @@ -863,24 +848,24 @@ namespace WebSocketSharp.Server } /// - /// Tries to get a WebSocket session information with the specified . + /// Tries to get a WebSocket session information with the specified + /// . /// /// /// true if the session is successfully found; otherwise, false. /// /// - /// A that contains an ID of the session to find. + /// A that represents the ID of the session to get. /// /// - /// When this method returns, a instance that contains - /// the session information if the session is successfully found; otherwise, . - /// This parameter is passed uninitialized. + /// When this method returns, a instance that + /// represents the session if it's successfully found; otherwise, + /// . This parameter is passed uninitialized. /// public bool TryGetSession (string id, out IWebSocketSession session) { var msg = _state.CheckIfStarted () ?? id.CheckIfValidSessionID (); - if (msg != null) - { + if (msg != null) { _logger.Error (msg); session = null;