Refactored a few for WebSocketSessionManager.cs
This commit is contained in:
parent
7d168515d1
commit
425d1387a0
@ -170,8 +170,8 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the manager cleans up the inactive sessions
|
||||
/// in the WebSocket service periodically.
|
||||
/// Gets a value indicating whether the manager cleans up the inactive sessions in
|
||||
/// the WebSocket service periodically.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the manager cleans up the inactive sessions every 60 seconds;
|
||||
@ -292,14 +292,14 @@ namespace WebSocketSharp.Server
|
||||
|
||||
private bool tryGetSession (string id, out IWebSocketSession session)
|
||||
{
|
||||
bool res;
|
||||
bool ret;
|
||||
lock (_sync)
|
||||
res = _sessions.TryGetValue (id, out session);
|
||||
ret = _sessions.TryGetValue (id, out session);
|
||||
|
||||
if (!res)
|
||||
_logger.Error ("A session with the specified ID isn't found.\nID: " + id);
|
||||
if (!ret)
|
||||
_logger.Error ("A session with the specified ID isn't found:\n ID: " + id);
|
||||
|
||||
return res;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -343,15 +343,15 @@ namespace WebSocketSharp.Server
|
||||
|
||||
internal Dictionary<string, bool> Broadping (byte[] frameAsBytes, TimeSpan timeout)
|
||||
{
|
||||
var res = new Dictionary<string, bool> ();
|
||||
var ret = new Dictionary<string, bool> ();
|
||||
foreach (var session in Sessions) {
|
||||
if (_state != ServerState.Start)
|
||||
break;
|
||||
|
||||
res.Add (session.ID, session.Context.WebSocket.Ping (frameAsBytes, timeout));
|
||||
ret.Add (session.ID, session.Context.WebSocket.Ping (frameAsBytes, timeout));
|
||||
}
|
||||
|
||||
return res;
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal bool Remove (string id)
|
||||
@ -386,10 +386,10 @@ namespace WebSocketSharp.Server
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary <paramref name="data"/> to every client in the WebSocket service.
|
||||
/// Sends binary <paramref name="data"/> to every client in the WebSocket service.
|
||||
/// </summary>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that represents the binary data to broadcast.
|
||||
/// An array of <see cref="byte"/> that represents the binary data to send.
|
||||
/// </param>
|
||||
public void Broadcast (byte[] data)
|
||||
{
|
||||
@ -406,10 +406,10 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a text <paramref name="data"/> to every client in the WebSocket service.
|
||||
/// Sends text <paramref name="data"/> to every client in the WebSocket service.
|
||||
/// </summary>
|
||||
/// <param name="data">
|
||||
/// A <see cref="string"/> that represents the text data to broadcast.
|
||||
/// A <see cref="string"/> that represents the text data to send.
|
||||
/// </param>
|
||||
public void Broadcast (string data)
|
||||
{
|
||||
@ -419,26 +419,26 @@ namespace WebSocketSharp.Server
|
||||
return;
|
||||
}
|
||||
|
||||
var rawData = Encoding.UTF8.GetBytes (data);
|
||||
if (rawData.LongLength <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.Text, rawData, null);
|
||||
var bytes = Encoding.UTF8.GetBytes (data);
|
||||
if (bytes.LongLength <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.Text, bytes, null);
|
||||
else
|
||||
broadcast (Opcode.Text, new MemoryStream (rawData), null);
|
||||
broadcast (Opcode.Text, new MemoryStream (bytes), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary <paramref name="data"/> asynchronously to every client
|
||||
/// in the WebSocket service.
|
||||
/// Sends binary <paramref name="data"/> asynchronously to every client in
|
||||
/// the WebSocket service.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the send to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that represents the binary data to broadcast.
|
||||
/// An array of <see cref="byte"/> that represents the binary data to send.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// An <see cref="Action"/> delegate that references the method(s) called when
|
||||
/// the broadcast is complete.
|
||||
/// the send is complete.
|
||||
/// </param>
|
||||
public void BroadcastAsync (byte[] data, Action completed)
|
||||
{
|
||||
@ -455,18 +455,18 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a text <paramref name="data"/> asynchronously to every client
|
||||
/// in the WebSocket service.
|
||||
/// Sends text <paramref name="data"/> asynchronously to every client in
|
||||
/// the WebSocket service.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the send to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="data">
|
||||
/// A <see cref="string"/> that represents the text data to broadcast.
|
||||
/// A <see cref="string"/> that represents the text data to send.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// An <see cref="Action"/> delegate that references the method(s) called when
|
||||
/// the broadcast is complete.
|
||||
/// the send is complete.
|
||||
/// </param>
|
||||
public void BroadcastAsync (string data, Action completed)
|
||||
{
|
||||
@ -476,29 +476,29 @@ namespace WebSocketSharp.Server
|
||||
return;
|
||||
}
|
||||
|
||||
var rawData = Encoding.UTF8.GetBytes (data);
|
||||
if (rawData.LongLength <= WebSocket.FragmentLength)
|
||||
broadcastAsync (Opcode.Text, rawData, completed);
|
||||
var bytes = Encoding.UTF8.GetBytes (data);
|
||||
if (bytes.LongLength <= WebSocket.FragmentLength)
|
||||
broadcastAsync (Opcode.Text, bytes, completed);
|
||||
else
|
||||
broadcastAsync (Opcode.Text, new MemoryStream (rawData), completed);
|
||||
broadcastAsync (Opcode.Text, new MemoryStream (bytes), completed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary data from the specified <see cref="Stream"/> asynchronously
|
||||
/// to every client in the WebSocket service.
|
||||
/// Sends binary data from the specified <see cref="Stream"/> asynchronously to
|
||||
/// every client in the WebSocket service.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the send to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="stream">
|
||||
/// A <see cref="Stream"/> from which contains the binary data to broadcast.
|
||||
/// A <see cref="Stream"/> from which contains the binary data to send.
|
||||
/// </param>
|
||||
/// <param name="length">
|
||||
/// An <see cref="int"/> that represents the number of bytes to broadcast.
|
||||
/// An <see cref="int"/> that represents the number of bytes to send.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// An <see cref="Action"/> delegate that references the method(s) called when
|
||||
/// the broadcast is complete.
|
||||
/// the send is complete.
|
||||
/// </param>
|
||||
public void BroadcastAsync (Stream stream, int length, Action completed)
|
||||
{
|
||||
@ -523,7 +523,7 @@ namespace WebSocketSharp.Server
|
||||
if (len < length)
|
||||
_logger.Warn (
|
||||
String.Format (
|
||||
"The data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}",
|
||||
"The data with 'length' cannot be read from 'stream':\n expected: {0}\n actual: {1}",
|
||||
length,
|
||||
len));
|
||||
|
||||
@ -555,8 +555,8 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a Ping with the specified <paramref name="message"/> to every client
|
||||
/// in the WebSocket service.
|
||||
/// Sends a Ping with the specified <paramref name="message"/> to every client in
|
||||
/// the WebSocket service.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <c>Dictionary<string, bool></c> that contains a collection of pairs of
|
||||
@ -654,8 +654,8 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a Ping with the specified <paramref name="message"/> to the client
|
||||
/// on the session with the specified <paramref name="id"/>.
|
||||
/// Sends a Ping with the specified <paramref name="message"/> to the client on
|
||||
/// the session with the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the manager receives a Pong from the client in a time;
|
||||
@ -674,8 +674,8 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a binary <paramref name="data"/> to the client on the session
|
||||
/// with the specified <paramref name="id"/>.
|
||||
/// Sends binary <paramref name="data"/> to the client on the session with
|
||||
/// the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that represents the binary data to send.
|
||||
@ -691,8 +691,8 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a text <paramref name="data"/> to the client on the session
|
||||
/// with the specified <paramref name="id"/>.
|
||||
/// Sends text <paramref name="data"/> to the client on the session with
|
||||
/// the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">
|
||||
/// A <see cref="string"/> that represents the text data to send.
|
||||
@ -708,8 +708,8 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a binary <paramref name="data"/> asynchronously to the client on the session
|
||||
/// with the specified <paramref name="id"/>.
|
||||
/// Sends binary <paramref name="data"/> asynchronously to the client on
|
||||
/// the session with the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method doesn't wait for the send to be complete.
|
||||
@ -733,8 +733,8 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a text <paramref name="data"/> asynchronously to the client on the session
|
||||
/// with the specified <paramref name="id"/>.
|
||||
/// Sends text <paramref name="data"/> asynchronously to the client on
|
||||
/// the session with the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method doesn't wait for the send to be complete.
|
||||
@ -758,8 +758,8 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a binary data from the specified <see cref="Stream"/> asynchronously
|
||||
/// to the client on the session with the specified <paramref name="id"/>.
|
||||
/// Sends binary data from the specified <see cref="Stream"/> asynchronously to
|
||||
/// the client on the session with the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method doesn't wait for the send to be complete.
|
||||
|
Loading…
Reference in New Issue
Block a user