Modified checking if can send
This commit is contained in:
@@ -276,6 +276,11 @@ namespace WebSocketSharp.Server
|
||||
state => broadcast (opcode, stream, completed));
|
||||
}
|
||||
|
||||
private string checkIfCanSend (Func<string> checkParams)
|
||||
{
|
||||
return _state.CheckIfStart () ?? checkParams ();
|
||||
}
|
||||
|
||||
private static string createID ()
|
||||
{
|
||||
return Guid.NewGuid ().ToString ("N");
|
||||
@@ -398,15 +403,16 @@ namespace WebSocketSharp.Server
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a binary <paramref name="data"/> to all clients of the
|
||||
/// WebSocket service.
|
||||
/// Broadcasts a binary <paramref name="data"/> to all clients
|
||||
/// of the WebSocket service.
|
||||
/// </summary>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that contains the binary data to broadcast.
|
||||
/// An array of <see cref="byte"/> that represents the binary data
|
||||
/// to broadcast.
|
||||
/// </param>
|
||||
public void Broadcast (byte [] data)
|
||||
{
|
||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
|
||||
var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return;
|
||||
@@ -419,15 +425,15 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a text <paramref name="data"/> to all clients of the WebSocket
|
||||
/// service.
|
||||
/// Broadcasts a text <paramref name="data"/> to all clients
|
||||
/// of the WebSocket service.
|
||||
/// </summary>
|
||||
/// <param name="data">
|
||||
/// A <see cref="string"/> that represents the text data to broadcast.
|
||||
/// </param>
|
||||
public void Broadcast (string data)
|
||||
{
|
||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
|
||||
var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return;
|
||||
@@ -448,7 +454,8 @@ namespace WebSocketSharp.Server
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that contains the binary data to broadcast.
|
||||
/// An array of <see cref="byte"/> that represents the binary data
|
||||
/// to broadcast.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// A <see cref="Action"/> delegate that references the method(s) called when
|
||||
@@ -456,7 +463,7 @@ namespace WebSocketSharp.Server
|
||||
/// </param>
|
||||
public void BroadcastAsync (byte [] data, Action completed)
|
||||
{
|
||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
|
||||
var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return;
|
||||
@@ -469,8 +476,8 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a text <paramref name="data"/> asynchronously to all clients of
|
||||
/// the WebSocket service.
|
||||
/// Broadcasts a text <paramref name="data"/> asynchronously to all clients
|
||||
/// of the WebSocket service.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
@@ -484,7 +491,7 @@ namespace WebSocketSharp.Server
|
||||
/// </param>
|
||||
public void BroadcastAsync (string data, Action completed)
|
||||
{
|
||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
|
||||
var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return;
|
||||
@@ -505,8 +512,7 @@ namespace WebSocketSharp.Server
|
||||
/// This method doesn't wait for the broadcast to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="stream">
|
||||
/// A <see cref="Stream"/> object from which contains the binary data to
|
||||
/// broadcast.
|
||||
/// A <see cref="Stream"/> from which contains the binary data to broadcast.
|
||||
/// </param>
|
||||
/// <param name="length">
|
||||
/// An <see cref="int"/> that represents the number of bytes to broadcast.
|
||||
@@ -517,9 +523,9 @@ namespace WebSocketSharp.Server
|
||||
/// </param>
|
||||
public void BroadcastAsync (Stream stream, int length, Action completed)
|
||||
{
|
||||
var msg = _state.CheckIfStarted () ??
|
||||
stream.CheckIfCanRead () ??
|
||||
(length < 1 ? "'length' must be greater than 0." : null);
|
||||
var msg = checkIfCanSend (
|
||||
() => stream.CheckIfCanRead () ??
|
||||
(length < 1 ? "'length' must be greater than 0." : null));
|
||||
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
@@ -560,7 +566,7 @@ namespace WebSocketSharp.Server
|
||||
/// </returns>
|
||||
public Dictionary<string, bool> Broadping ()
|
||||
{
|
||||
var msg = _state.CheckIfStarted ();
|
||||
var msg = _state.CheckIfStart ();
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
return null;
|
||||
@@ -587,8 +593,9 @@ namespace WebSocketSharp.Server
|
||||
return Broadping ();
|
||||
|
||||
byte [] data = null;
|
||||
var msg = _state.CheckIfStarted () ??
|
||||
(data = Encoding.UTF8.GetBytes (message)).CheckIfValidControlData ("message");
|
||||
var msg = checkIfCanSend (
|
||||
() => (data = Encoding.UTF8.GetBytes (message))
|
||||
.CheckIfValidControlData ("message"));
|
||||
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
@@ -695,15 +702,14 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a binary <paramref name="data"/> to the client associated with the
|
||||
/// specified <paramref name="id"/>.
|
||||
/// Sends a binary <paramref name="data"/> to the client on the session
|
||||
/// with the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that represents the ID of the session to send the
|
||||
/// data to.
|
||||
/// A <see cref="string"/> that represents the ID of the session to find.
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that contains the binary data to send.
|
||||
/// An array of <see cref="byte"/> that represents the binary data to send.
|
||||
/// </param>
|
||||
public void SendTo (string id, byte [] data)
|
||||
{
|
||||
@@ -713,11 +719,11 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a text <paramref name="data"/> to the client associated with the
|
||||
/// specified <paramref name="id"/>.
|
||||
/// Sends a text <paramref name="data"/> to the client on the session
|
||||
/// with the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that represents the ID of the session to send the
|
||||
/// A <see cref="string"/> that represents the ID of the session to find.
|
||||
/// data to.
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
@@ -732,17 +738,16 @@ namespace WebSocketSharp.Server
|
||||
|
||||
/// <summary>
|
||||
/// Sends a binary <paramref name="data"/> asynchronously to the client
|
||||
/// associated with the specified <paramref name="id"/>.
|
||||
/// on the session with the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method doesn't wait for the send to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that represents the ID of the session to send the
|
||||
/// data to.
|
||||
/// A <see cref="string"/> that represents the ID of the session to find.
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that contains the binary data to send.
|
||||
/// An array of <see cref="byte"/> that represents the binary data to send.
|
||||
/// </param>
|
||||
/// <param name="completed">
|
||||
/// An Action<bool> delegate that references the method(s) called when
|
||||
@@ -759,14 +764,13 @@ namespace WebSocketSharp.Server
|
||||
|
||||
/// <summary>
|
||||
/// Sends a text <paramref name="data"/> asynchronously to the client
|
||||
/// associated with the specified <paramref name="id"/>.
|
||||
/// on the session with the specified <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method doesn't wait for the send to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that represents the ID of the session to send the
|
||||
/// data to.
|
||||
/// A <see cref="string"/> that represents the ID of the session to find.
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
/// A <see cref="string"/> that represents the text data to send.
|
||||
@@ -786,17 +790,16 @@ namespace WebSocketSharp.Server
|
||||
|
||||
/// <summary>
|
||||
/// Sends a binary data from the specified <see cref="Stream"/> asynchronously
|
||||
/// to the client associated with the specified <paramref name="id"/>.
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
/// <param name="id">
|
||||
/// A <see cref="string"/> that represents the ID of the session to send the
|
||||
/// data to.
|
||||
/// A <see cref="string"/> that represents the ID of the session to find.
|
||||
/// </param>
|
||||
/// <param name="stream">
|
||||
/// A <see cref="Stream"/> object from which contains the binary data to send.
|
||||
/// 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 send.
|
||||
@@ -864,7 +867,7 @@ namespace WebSocketSharp.Server
|
||||
/// </param>
|
||||
public bool TryGetSession (string id, out IWebSocketSession session)
|
||||
{
|
||||
var msg = _state.CheckIfStarted () ?? id.CheckIfValidSessionID ();
|
||||
var msg = _state.CheckIfStart () ?? id.CheckIfValidSessionID ();
|
||||
if (msg != null) {
|
||||
_logger.Error (msg);
|
||||
session = null;
|
||||
|
||||
Reference in New Issue
Block a user