Refactored WebSocketServiceHostManager.cs
This commit is contained in:
parent
418ec8bc2f
commit
d188670fb2
@ -37,7 +37,7 @@ using WebSocketSharp.Net;
|
||||
namespace WebSocketSharp.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the WebSocket services provided by the <see cref="HttpServer"/> and
|
||||
/// Manages the WebSocket services provided by the <see cref="HttpServer"/> or
|
||||
/// <see cref="WebSocketServer"/>.
|
||||
/// </summary>
|
||||
public class WebSocketServiceHostManager
|
||||
@ -73,15 +73,15 @@ namespace WebSocketSharp.Server
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of the WebSocket services provided by the WebSocket server.
|
||||
/// Gets the number of the WebSocket services provided by the server.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// An <see cref="int"/> that contains the number of the WebSocket services.
|
||||
/// An <see cref="int"/> that represents the number of the WebSocket services
|
||||
/// provided by the server.
|
||||
/// </value>
|
||||
public int Count {
|
||||
get {
|
||||
lock (_sync)
|
||||
{
|
||||
lock (_sync) {
|
||||
return _serviceHosts.Count;
|
||||
}
|
||||
}
|
||||
@ -91,11 +91,13 @@ namespace WebSocketSharp.Server
|
||||
/// Gets a WebSocket service host with the specified <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="WebSocketServiceHost"/> instance that represents the service host
|
||||
/// if the service is successfully found; otherwise, <see langword="null"/>.
|
||||
/// A <see cref="WebSocketServiceHost"/> instance that represents the
|
||||
/// WebSocket service host if it's successfully found; otherwise,
|
||||
/// <see langword="null"/>.
|
||||
/// </value>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
public WebSocketServiceHost this [string servicePath] {
|
||||
get {
|
||||
@ -107,12 +109,12 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the manager cleans up periodically the every inactive session
|
||||
/// to the WebSocket services provided by the WebSocket server.
|
||||
/// Gets a value indicating whether the manager cleans up periodically the
|
||||
/// every inactive session to the WebSocket services provided by the server.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the manager cleans up periodically the every inactive session to the WebSocket
|
||||
/// services; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the manager cleans up periodically the every inactive
|
||||
/// session to the WebSocket services; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool KeepClean {
|
||||
get {
|
||||
@ -120,8 +122,7 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
internal set {
|
||||
lock (_sync)
|
||||
{
|
||||
lock (_sync) {
|
||||
if (!(value ^ _keepClean))
|
||||
return;
|
||||
|
||||
@ -133,48 +134,47 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of the WebSocket service hosts managed by the WebSocket server.
|
||||
/// Gets the collection of the WebSocket service hosts managed by the server.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// An IEnumerable<WebSocketServiceHost> that contains the collection of the WebSocket
|
||||
/// service hosts.
|
||||
/// An IEnumerable<WebSocketServiceHost> that contains the collection of
|
||||
/// the WebSocket service hosts.
|
||||
/// </value>
|
||||
public IEnumerable<WebSocketServiceHost> ServiceHosts {
|
||||
get {
|
||||
lock (_sync)
|
||||
{
|
||||
lock (_sync) {
|
||||
return _serviceHosts.Values.ToList ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of every path to the WebSocket services provided by the WebSocket server.
|
||||
/// Gets the collection of every path to the WebSocket services provided by
|
||||
/// the server.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// An IEnumerable<string> that contains the collection of every path to the WebSocket services.
|
||||
/// An IEnumerable<string> that contains the collection of every path to
|
||||
/// the WebSocket services.
|
||||
/// </value>
|
||||
public IEnumerable<string> ServicePaths {
|
||||
get {
|
||||
lock (_sync)
|
||||
{
|
||||
lock (_sync) {
|
||||
return _serviceHosts.Keys.ToList ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of the sessions to the every WebSocket service
|
||||
/// provided by the WebSocket server.
|
||||
/// Gets the number of the sessions to the every WebSocket service provided by
|
||||
/// the server.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// An <see cref="int"/> that contains the session count of the WebSocket server.
|
||||
/// An <see cref="int"/> that represents the session count of the server.
|
||||
/// </value>
|
||||
public int SessionCount {
|
||||
get {
|
||||
var count = 0;
|
||||
foreach (var host in ServiceHosts)
|
||||
{
|
||||
foreach (var host in ServiceHosts) {
|
||||
if (_state != ServerState.START)
|
||||
break;
|
||||
|
||||
@ -193,8 +193,7 @@ namespace WebSocketSharp.Server
|
||||
{
|
||||
var cache = new Dictionary<CompressionMethod, byte []> ();
|
||||
try {
|
||||
foreach (var host in ServiceHosts)
|
||||
{
|
||||
foreach (var host in ServiceHosts) {
|
||||
if (_state != ServerState.START)
|
||||
break;
|
||||
|
||||
@ -216,8 +215,7 @@ namespace WebSocketSharp.Server
|
||||
{
|
||||
var cache = new Dictionary<CompressionMethod, Stream> ();
|
||||
try {
|
||||
foreach (var host in ServiceHosts)
|
||||
{
|
||||
foreach (var host in ServiceHosts) {
|
||||
if (_state != ServerState.START)
|
||||
break;
|
||||
|
||||
@ -240,33 +238,26 @@ namespace WebSocketSharp.Server
|
||||
|
||||
private void broadcastAsync (Opcode opcode, byte [] data, Action completed)
|
||||
{
|
||||
WaitCallback callback = state =>
|
||||
{
|
||||
broadcast (opcode, data, completed);
|
||||
};
|
||||
|
||||
ThreadPool.QueueUserWorkItem (callback);
|
||||
ThreadPool.QueueUserWorkItem (
|
||||
state => broadcast (opcode, data, completed));
|
||||
}
|
||||
|
||||
private void broadcastAsync (Opcode opcode, Stream stream, Action completed)
|
||||
{
|
||||
WaitCallback callback = state =>
|
||||
{
|
||||
broadcast (opcode, stream, completed);
|
||||
};
|
||||
|
||||
ThreadPool.QueueUserWorkItem (callback);
|
||||
ThreadPool.QueueUserWorkItem (
|
||||
state => broadcast (opcode, stream, completed));
|
||||
}
|
||||
|
||||
private Dictionary<string, Dictionary<string, bool>> broadping (byte [] frameAsBytes, int timeOut)
|
||||
private Dictionary<string, Dictionary<string, bool>> broadping (
|
||||
byte [] frameAsBytes, int timeOut)
|
||||
{
|
||||
var result = new Dictionary<string, Dictionary<string, bool>> ();
|
||||
foreach (var host in ServiceHosts)
|
||||
{
|
||||
foreach (var host in ServiceHosts) {
|
||||
if (_state != ServerState.START)
|
||||
break;
|
||||
|
||||
result.Add (host.ServicePath, host.Sessions.Broadping (frameAsBytes, timeOut));
|
||||
result.Add (
|
||||
host.ServicePath, host.Sessions.Broadping (frameAsBytes, timeOut));
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -278,11 +269,9 @@ namespace WebSocketSharp.Server
|
||||
|
||||
internal void Add (string servicePath, WebSocketServiceHost serviceHost)
|
||||
{
|
||||
lock (_sync)
|
||||
{
|
||||
lock (_sync) {
|
||||
WebSocketServiceHost host;
|
||||
if (_serviceHosts.TryGetValue (servicePath, out host))
|
||||
{
|
||||
if (_serviceHosts.TryGetValue (servicePath, out host)) {
|
||||
_logger.Error (
|
||||
"A WebSocket service with the specified path already exists.\npath: " + servicePath);
|
||||
return;
|
||||
@ -298,11 +287,10 @@ namespace WebSocketSharp.Server
|
||||
internal bool Remove (string servicePath)
|
||||
{
|
||||
servicePath = HttpUtility.UrlDecode (servicePath).TrimEndSlash ();
|
||||
|
||||
WebSocketServiceHost host;
|
||||
lock (_sync)
|
||||
{
|
||||
if (!_serviceHosts.TryGetValue (servicePath, out host))
|
||||
{
|
||||
lock (_sync) {
|
||||
if (!_serviceHosts.TryGetValue (servicePath, out host)) {
|
||||
_logger.Error (
|
||||
"A WebSocket service with the specified path not found.\npath: " + servicePath);
|
||||
return false;
|
||||
@ -312,15 +300,15 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
if (host.Sessions.State == ServerState.START)
|
||||
host.Sessions.Stop (((ushort) CloseStatusCode.AWAY).ToByteArrayInternally (ByteOrder.BIG), true);
|
||||
host.Sessions.Stop (
|
||||
((ushort) CloseStatusCode.AWAY).ToByteArrayInternally (ByteOrder.BIG), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void Start ()
|
||||
{
|
||||
lock (_sync)
|
||||
{
|
||||
lock (_sync) {
|
||||
foreach (var host in _serviceHosts.Values)
|
||||
host.Sessions.Start ();
|
||||
|
||||
@ -330,15 +318,15 @@ namespace WebSocketSharp.Server
|
||||
|
||||
internal void Stop (byte [] data, bool send)
|
||||
{
|
||||
lock (_sync)
|
||||
{
|
||||
lock (_sync) {
|
||||
_state = ServerState.SHUTDOWN;
|
||||
|
||||
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;
|
||||
|
||||
foreach (var host in _serviceHosts.Values)
|
||||
host.Sessions.Stop (args, frameAsBytes);
|
||||
@ -349,17 +337,19 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
}
|
||||
|
||||
internal bool TryGetServiceHostInternally (string servicePath, out WebSocketServiceHost serviceHost)
|
||||
internal bool TryGetServiceHostInternally (
|
||||
string servicePath, out WebSocketServiceHost serviceHost)
|
||||
{
|
||||
servicePath = HttpUtility.UrlDecode (servicePath).TrimEndSlash ();
|
||||
|
||||
bool result;
|
||||
lock (_sync)
|
||||
{
|
||||
lock (_sync) {
|
||||
result = _serviceHosts.TryGetValue (servicePath, out serviceHost);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
_logger.Error ("A WebSocket service with the specified path not found.\npath: " + servicePath);
|
||||
_logger.Error (
|
||||
"A WebSocket service with the specified path not found.\npath: " + servicePath);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -369,54 +359,66 @@ namespace WebSocketSharp.Server
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary <paramref name="data"/> to all clients of the WebSocket services
|
||||
/// provided by a WebSocket server.
|
||||
/// Broadcasts a binary <paramref name="data"/> to all clients of the
|
||||
/// WebSocket services provided by the server.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that contains a binary data to broadcast.
|
||||
/// An array of <see cref="byte"/> that contains the binary data to broadcast.
|
||||
/// </param>
|
||||
public void Broadcast (byte [] data)
|
||||
{
|
||||
Broadcast (data, null);
|
||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.LongLength <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.BINARY, data, null);
|
||||
else
|
||||
broadcast (Opcode.BINARY, new MemoryStream (data), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a text <paramref name="data"/> to all clients of the WebSocket services
|
||||
/// provided by a WebSocket server.
|
||||
/// Broadcasts a text <paramref name="data"/> to all clients of the WebSocket
|
||||
/// services provided by the server.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="data">
|
||||
/// A <see cref="string"/> that contains a text data to broadcast.
|
||||
/// A <see cref="string"/> that represents the text data to broadcast.
|
||||
/// </param>
|
||||
public void Broadcast (string data)
|
||||
{
|
||||
Broadcast (data, null);
|
||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return;
|
||||
}
|
||||
|
||||
var rawData = Encoding.UTF8.GetBytes (data);
|
||||
if (rawData.LongLength <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.TEXT, rawData, null);
|
||||
else
|
||||
broadcast (Opcode.TEXT, new MemoryStream (rawData), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary <paramref name="data"/> to all clients of the WebSocket services
|
||||
/// provided by a WebSocket server.
|
||||
/// Broadcasts a binary <paramref name="data"/> asynchronously to all clients
|
||||
/// of the WebSocket services provided by the server.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that contains a binary data to broadcast.
|
||||
/// An array of <see cref="byte"/> that contains the binary data to broadcast.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// A <see cref="Action"/> delegate that references the method(s) called when
|
||||
/// the broadcast is complete.
|
||||
/// </param>
|
||||
public void Broadcast (byte [] data, Action completed)
|
||||
public void BroadcastAsync (byte [] data, Action completed)
|
||||
{
|
||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
|
||||
if (msg != null)
|
||||
{
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return;
|
||||
}
|
||||
@ -428,24 +430,23 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a text <paramref name="data"/> to all clients of the WebSocket services
|
||||
/// provided by a WebSocket server.
|
||||
/// Broadcasts a text <paramref name="data"/> asynchronously to all clients of
|
||||
/// the WebSocket services provided by the server.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="data">
|
||||
/// A <see cref="string"/> that contains a text data to broadcast.
|
||||
/// A <see cref="string"/> that represents the text data to broadcast.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// A <see cref="Action"/> delegate that references the method(s) called when
|
||||
/// the broadcast is complete.
|
||||
/// </param>
|
||||
public void Broadcast (string data, Action completed)
|
||||
public void BroadcastAsync (string data, Action completed)
|
||||
{
|
||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
|
||||
if (msg != null)
|
||||
{
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return;
|
||||
}
|
||||
@ -458,92 +459,74 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary data from the specified <see cref="Stream"/> to all clients
|
||||
/// of the WebSocket services provided by a WebSocket server.
|
||||
/// Broadcasts a binary data from the specified <see cref="Stream"/>
|
||||
/// asynchronously to all clients of the WebSocket services provided by the
|
||||
/// server.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="stream">
|
||||
/// A <see cref="Stream"/> object from which contains a binary data to broadcast.
|
||||
/// A <see cref="Stream"/> object from which contains the binary data to
|
||||
/// broadcast.
|
||||
/// </param>
|
||||
/// <param name="length">
|
||||
/// An <see cref="int"/> that contains the number of bytes to broadcast.
|
||||
/// </param>
|
||||
public void Broadcast (Stream stream, int length)
|
||||
{
|
||||
Broadcast (stream, length, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary data from the specified <see cref="Stream"/> to all clients
|
||||
/// of the WebSocket services provided by a WebSocket server.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="stream">
|
||||
/// A <see cref="Stream"/> object from which contains a binary data to broadcast.
|
||||
/// </param>
|
||||
/// <param name="length">
|
||||
/// An <see cref="int"/> that contains the number of bytes to broadcast.
|
||||
/// An <see cref="int"/> that represents the number of bytes to broadcast.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// A <see cref="Action"/> delegate that references the method(s) called when
|
||||
/// the broadcast is complete.
|
||||
/// </param>
|
||||
public void Broadcast (Stream stream, int length, Action completed)
|
||||
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);
|
||||
else
|
||||
broadcast (Opcode.BINARY, new MemoryStream (data), completed);
|
||||
},
|
||||
ex =>
|
||||
{
|
||||
ex => {
|
||||
_logger.Fatal (ex.ToString ());
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary <paramref name="data"/> to all clients of a WebSocket service
|
||||
/// with the specified <paramref name="servicePath"/>.
|
||||
/// Broadcasts a binary <paramref name="data"/> to all clients of the
|
||||
/// WebSocket service with the specified <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that contains a binary data to broadcast.
|
||||
/// An array of <see cref="byte"/> that contains the binary data to broadcast.
|
||||
/// </param>
|
||||
public void BroadcastTo (string servicePath, byte [] data)
|
||||
{
|
||||
@ -551,17 +534,18 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a text <paramref name="data"/> to all clients of a WebSocket service
|
||||
/// with the specified <paramref name="servicePath"/>.
|
||||
/// Broadcasts a text <paramref name="data"/> to all clients of the WebSocket
|
||||
/// service with the specified <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
/// A <see cref="string"/> that contains a text data to broadcast.
|
||||
/// A <see cref="string"/> that represents the text data to broadcast.
|
||||
/// </param>
|
||||
public void BroadcastTo (string servicePath, string data)
|
||||
{
|
||||
@ -569,17 +553,18 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary <paramref name="data"/> to all clients of a WebSocket service
|
||||
/// with the specified <paramref name="servicePath"/>.
|
||||
/// Broadcasts a binary <paramref name="data"/> to all clients of the
|
||||
/// WebSocket service with the specified <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that contains a binary data to broadcast.
|
||||
/// An array of <see cref="byte"/> that contains the binary data to broadcast.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// A <see cref="Action"/> delegate that references the method(s) called when
|
||||
@ -593,17 +578,18 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a text <paramref name="data"/> to all clients of a WebSocket service
|
||||
/// with the specified <paramref name="servicePath"/>.
|
||||
/// Broadcasts a text <paramref name="data"/> to all clients of the WebSocket
|
||||
/// service with the specified <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
/// A <see cref="string"/> that contains a text data to broadcast.
|
||||
/// A <see cref="string"/> that represents the text data to broadcast.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// A <see cref="Action"/> delegate that references the method(s) called when
|
||||
@ -617,41 +603,22 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary data from the specified <see cref="Stream"/> to all clients
|
||||
/// of a WebSocket service with the specified <paramref name="servicePath"/>.
|
||||
/// Broadcasts a binary data from the specified <see cref="Stream"/> to all
|
||||
/// clients of the WebSocket service with the specified <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="stream">
|
||||
/// A <see cref="Stream"/> object from which contains a binary data to broadcast.
|
||||
/// A <see cref="Stream"/> object from which contains the binary data to
|
||||
/// broadcast.
|
||||
/// </param>
|
||||
/// <param name="length">
|
||||
/// An <see cref="int"/> that contains the number of bytes to broadcast.
|
||||
/// </param>
|
||||
public void BroadcastTo (string servicePath, Stream stream, int length)
|
||||
{
|
||||
BroadcastTo (servicePath, stream, length, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary data from the specified <see cref="Stream"/> to all clients
|
||||
/// of a WebSocket service with the specified <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// </param>
|
||||
/// <param name="stream">
|
||||
/// A <see cref="Stream"/> object from which contains a binary data to broadcast.
|
||||
/// </param>
|
||||
/// <param name="length">
|
||||
/// An <see cref="int"/> that contains the number of bytes to broadcast.
|
||||
/// An <see cref="int"/> that represents the number of bytes to broadcast.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// A <see cref="Action"/> delegate that references the method(s) called when
|
||||
@ -666,18 +633,19 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends Pings to all clients of the WebSocket services provided by a WebSocket server.
|
||||
/// Sends Pings to all clients of the WebSocket services provided by the
|
||||
/// server.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A Dictionary<string, Dictionary<string, bool>> that contains the collection of
|
||||
/// service paths and pairs of session ID and value indicating whether each WebSocket service
|
||||
/// received a Pong from each client in a time.
|
||||
/// A Dictionary<string, Dictionary<string, bool>> that contains
|
||||
/// the collection of service paths and pairs of session ID and value
|
||||
/// indicating whether each WebSocket service received a Pong from each client
|
||||
/// in a time.
|
||||
/// </returns>
|
||||
public Dictionary<string, Dictionary<string, bool>> Broadping ()
|
||||
{
|
||||
var msg = _state.CheckIfStarted ();
|
||||
if (msg != null)
|
||||
{
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return null;
|
||||
}
|
||||
@ -686,17 +654,17 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends Pings with the specified <paramref name="message"/> to all clients of the WebSocket
|
||||
/// services provided by a WebSocket server.
|
||||
/// Sends Pings with the specified <paramref name="message"/> to all clients
|
||||
/// of the WebSocket services provided by the server.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A Dictionary<string, Dictionary<string, bool>> that contains the collection of
|
||||
/// service paths and pairs of session ID and value indicating whether each WebSocket service
|
||||
/// received a Pong from each client in a time.
|
||||
/// If <paramref name="message"/> is invalid, returns <see langword="null"/>.
|
||||
/// A Dictionary<string, Dictionary<string, bool>> that contains
|
||||
/// the collection of service paths and pairs of session ID and value
|
||||
/// indicating whether each WebSocket service received a Pong from each client
|
||||
/// in a time. If <paramref name="message"/> is invalid, returns <see langword="null"/>.
|
||||
/// </returns>
|
||||
/// <param name="message">
|
||||
/// A <see cref="string"/> that contains a message to broadcast.
|
||||
/// A <see cref="string"/> that represents the message to broadcast.
|
||||
/// </param>
|
||||
public Dictionary<string, Dictionary<string, bool>> Broadping (string message)
|
||||
{
|
||||
@ -707,26 +675,28 @@ 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends Pings to all clients of a WebSocket service with
|
||||
/// the specified <paramref name="servicePath"/>.
|
||||
/// Sends Pings to all clients of the WebSocket service with the specified
|
||||
/// <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// 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.
|
||||
/// If the WebSocket service not found, returns <see langword="null"/>.
|
||||
/// 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. If the WebSocket service not found,
|
||||
/// returns <see langword="null"/>.
|
||||
/// </returns>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
public Dictionary<string, bool> BroadpingTo (string servicePath)
|
||||
{
|
||||
@ -738,20 +708,23 @@ namespace WebSocketSharp.Server
|
||||
|
||||
/// <summary>
|
||||
/// Sends Pings with the specified <paramref name="message"/> to all clients
|
||||
/// of a WebSocket service with the specified <paramref name="servicePath"/>.
|
||||
/// of the WebSocket service with the specified <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// 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.
|
||||
/// If the WebSocket service not found, returns <see langword="null"/>.
|
||||
/// 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. If the WebSocket service not found,
|
||||
/// returns <see langword="null"/>.
|
||||
/// </returns>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="message">
|
||||
/// A <see cref="string"/> that contains a message to send.
|
||||
/// A <see cref="string"/> that represents the message to send.
|
||||
/// </param>
|
||||
public Dictionary<string, bool> BroadpingTo (string servicePath, string message)
|
||||
public Dictionary<string, bool> BroadpingTo (
|
||||
string servicePath, string message)
|
||||
{
|
||||
WebSocketServiceHost host;
|
||||
return TryGetServiceHost (servicePath, out host)
|
||||
@ -764,10 +737,11 @@ namespace WebSocketSharp.Server
|
||||
/// <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to a WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that contains a session ID to find.
|
||||
/// A <see cref="string"/> that represents the session ID to find.
|
||||
/// </param>
|
||||
public void CloseSession (string servicePath, string id)
|
||||
{
|
||||
@ -777,22 +751,24 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the session with the specified <paramref name="servicePath"/>, <paramref name="id"/>,
|
||||
/// <paramref name="code"/> and <paramref name="reason"/>.
|
||||
/// Closes the session with the specified <paramref name="servicePath"/>,
|
||||
/// <paramref name="id"/>, <paramref name="code"/> and <paramref name="reason"/>.
|
||||
/// </summary>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to a WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that contains a session ID to find.
|
||||
/// A <see cref="string"/> that represents the session ID to find.
|
||||
/// </param>
|
||||
/// <param name="code">
|
||||
/// A <see cref="ushort"/> that contains a status code indicating the reason for closure.
|
||||
/// A <see cref="ushort"/> that indicates the status code for closure.
|
||||
/// </param>
|
||||
/// <param name="reason">
|
||||
/// A <see cref="string"/> that contains the reason for closure.
|
||||
/// A <see cref="string"/> that represents the reason for closure.
|
||||
/// </param>
|
||||
public void CloseSession (string servicePath, string id, ushort code, string reason)
|
||||
public void CloseSession (
|
||||
string servicePath, string id, ushort code, string reason)
|
||||
{
|
||||
WebSocketServiceHost host;
|
||||
if (TryGetServiceHost (servicePath, out host))
|
||||
@ -800,22 +776,25 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the session with the specified <paramref name="servicePath"/>, <paramref name="id"/>,
|
||||
/// <paramref name="code"/> and <paramref name="reason"/>.
|
||||
/// Closes the session with the specified <paramref name="servicePath"/>,
|
||||
/// <paramref name="id"/>, <paramref name="code"/> and <paramref name="reason"/>.
|
||||
/// </summary>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to a WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that contains a session ID to find.
|
||||
/// A <see cref="string"/> that represents the session ID to find.
|
||||
/// </param>
|
||||
/// <param name="code">
|
||||
/// One of the <see cref="CloseStatusCode"/> values that indicate the status codes for closure.
|
||||
/// One of the <see cref="CloseStatusCode"/> values that indicate the status
|
||||
/// codes for closure.
|
||||
/// </param>
|
||||
/// <param name="reason">
|
||||
/// A <see cref="string"/> that contains the reason for closure.
|
||||
/// A <see cref="string"/> that represents the reason for closure.
|
||||
/// </param>
|
||||
public void CloseSession (string servicePath, string id, CloseStatusCode code, string reason)
|
||||
public void CloseSession (
|
||||
string servicePath, string id, CloseStatusCode code, string reason)
|
||||
{
|
||||
WebSocketServiceHost host;
|
||||
if (TryGetServiceHost (servicePath, out host))
|
||||
@ -823,48 +802,53 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a Ping to the client associated with the specified <paramref name="servicePath"/>
|
||||
/// and <paramref name="id"/>.
|
||||
/// Sends a Ping to the client associated with the specified
|
||||
/// <paramref name="servicePath"/> and <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the WebSocket service with <paramref name="servicePath"/> receives
|
||||
/// a Pong from the client in a time; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the WebSocket service with <paramref name="servicePath"/>
|
||||
/// receives a Pong from the client in a time; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that contains a session ID that represents the destination
|
||||
/// for the Ping.
|
||||
/// A <see cref="string"/> that represents the session ID that represents the
|
||||
/// destination for the Ping.
|
||||
/// </param>
|
||||
public bool PingTo (string servicePath, string id)
|
||||
{
|
||||
WebSocketServiceHost host;
|
||||
return TryGetServiceHost (servicePath, out host) && host.Sessions.PingTo (id);
|
||||
return TryGetServiceHost (servicePath, out host) &&
|
||||
host.Sessions.PingTo (id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a Ping with the specified <paramref name="message"/> to the client associated
|
||||
/// with the specified <paramref name="servicePath"/> and <paramref name="id"/>.
|
||||
/// Sends a Ping with the specified <paramref name="message"/> to the client
|
||||
/// associated with the specified <paramref name="servicePath"/> and
|
||||
/// <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the WebSocket service with <paramref name="servicePath"/> receives
|
||||
/// a Pong from the client in a time; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the WebSocket service with <paramref name="servicePath"/>
|
||||
/// receives a Pong from the client in a time; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that contains a session ID that represents the destination
|
||||
/// for the Ping.
|
||||
/// A <see cref="string"/> that represents the session ID that represents the
|
||||
/// destination for the Ping.
|
||||
/// </param>
|
||||
/// <param name="message">
|
||||
/// A <see cref="string"/> that contains a message to send.
|
||||
/// A <see cref="string"/> that represents the message to send.
|
||||
/// </param>
|
||||
public bool PingTo (string servicePath, string id, string message)
|
||||
{
|
||||
WebSocketServiceHost host;
|
||||
return TryGetServiceHost (servicePath, out host) && host.Sessions.PingTo (id, message);
|
||||
return TryGetServiceHost (servicePath, out host) &&
|
||||
host.Sessions.PingTo (id, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1014,24 +998,27 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get a WebSocket service host with the specified <paramref name="servicePath"/>.
|
||||
/// Tries to get a WebSocket service host with the specified
|
||||
/// <paramref name="servicePath"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the service is successfully found; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the WebSocket service host is successfully found;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <param name="servicePath">
|
||||
/// A <see cref="string"/> that contains an absolute path to the service to find.
|
||||
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||
/// service to find.
|
||||
/// </param>
|
||||
/// <param name="serviceHost">
|
||||
/// When this method returns, a <see cref="WebSocketServiceHost"/> instance that represents
|
||||
/// the service host if the service is successfully found; otherwise, <see langword="null"/>.
|
||||
/// This parameter is passed uninitialized.
|
||||
/// When this method returns, a <see cref="WebSocketServiceHost"/> instance
|
||||
/// that represents the WebSocket service host if it's successfully found;
|
||||
/// otherwise, <see langword="null"/>. This parameter is passed uninitialized.
|
||||
/// </param>
|
||||
public bool TryGetServiceHost (string servicePath, out WebSocketServiceHost serviceHost)
|
||||
public bool TryGetServiceHost (
|
||||
string servicePath, out WebSocketServiceHost serviceHost)
|
||||
{
|
||||
var msg = _state.CheckIfStarted () ?? servicePath.CheckIfValidServicePath ();
|
||||
if (msg != null)
|
||||
{
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
serviceHost = null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user