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