Modified some Send and Broadcast methods (e.g. Send (stream, length, dispose) -> Send (stream, length))

This commit is contained in:
sta
2013-10-16 00:18:05 +09:00
parent cbf73e9865
commit f6610352e2
6 changed files with 222 additions and 282 deletions

View File

@@ -315,22 +315,6 @@ namespace WebSocketSharp.Server
_websocket.Send (data, null);
}
/// <summary>
/// Sends a text <paramref name="data"/> to the client of the current
/// <see cref="WebSocketService"/> instance.
/// </summary>
/// <remarks>
/// This method does not wait for the send to be complete.
/// </remarks>
/// <param name="data">
/// A <see cref="string"/> that contains a text data to send.
/// </param>
protected void Send (string data)
{
if (_websocket != null)
_websocket.Send (data, null);
}
/// <summary>
/// Sends a binary data from the specified <see cref="FileInfo"/> to
/// the client of the current <see cref="WebSocketService"/> instance.
@@ -347,6 +331,22 @@ namespace WebSocketSharp.Server
_websocket.Send (file, null);
}
/// <summary>
/// Sends a text <paramref name="data"/> to the client of the current
/// <see cref="WebSocketService"/> instance.
/// </summary>
/// <remarks>
/// This method does not wait for the send to be complete.
/// </remarks>
/// <param name="data">
/// A <see cref="string"/> that contains a text data to send.
/// </param>
protected void Send (string data)
{
if (_websocket != null)
_websocket.Send (data, null);
}
/// <summary>
/// Sends a binary <paramref name="data"/> to the client of the current
/// <see cref="WebSocketService"/> instance.
@@ -369,28 +369,6 @@ namespace WebSocketSharp.Server
_websocket.Send (data, completed);
}
/// <summary>
/// Sends a text <paramref name="data"/> to the client of the current
/// <see cref="WebSocketService"/> instance.
/// </summary>
/// <remarks>
/// This method does not wait for the send to be complete.
/// </remarks>
/// <param name="data">
/// A <see cref="string"/> that contains a text data to send.
/// </param>
/// <param name="completed">
/// An Action&lt;bool&gt; delegate that references the method(s) called when
/// the send is complete.
/// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
/// complete successfully; otherwise, <c>false</c>.
/// </param>
protected void Send (string data, Action<bool> completed)
{
if (_websocket != null)
_websocket.Send (data, completed);
}
/// <summary>
/// Sends a binary data from the specified <see cref="FileInfo"/> to
/// the client of the current <see cref="WebSocketService"/> instance.
@@ -414,26 +392,25 @@ namespace WebSocketSharp.Server
}
/// <summary>
/// Sends a binary data from the specified <see cref="Stream"/> to
/// the client of the current <see cref="WebSocketService"/> instance.
/// Sends a text <paramref name="data"/> to the client of the current
/// <see cref="WebSocketService"/> instance.
/// </summary>
/// <remarks>
/// This method does not wait for the send to be complete.
/// </remarks>
/// <param name="stream">
/// A <see cref="Stream"/> object from which contains a binary data to send.
/// <param name="data">
/// A <see cref="string"/> that contains a text data to send.
/// </param>
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to send.
/// <param name="completed">
/// An Action&lt;bool&gt; delegate that references the method(s) called when
/// the send is complete.
/// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
/// complete successfully; otherwise, <c>false</c>.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data read;
/// otherwise, <c>false</c>.
/// </param>
protected void Send (Stream stream, int length, bool dispose)
protected void Send (string data, Action<bool> completed)
{
if (_websocket != null)
_websocket.Send (stream, length, dispose, null);
_websocket.Send (data, completed);
}
/// <summary>
@@ -449,9 +426,24 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to send.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data read;
/// otherwise, <c>false</c>.
protected void Send (Stream stream, int length)
{
if (_websocket != null)
_websocket.Send (stream, length, null);
}
/// <summary>
/// Sends a binary data from the specified <see cref="Stream"/> to
/// the client of the current <see cref="WebSocketService"/> instance.
/// </summary>
/// <remarks>
/// This method does not wait for the send to be complete.
/// </remarks>
/// <param name="stream">
/// A <see cref="Stream"/> object from which contains a binary data to send.
/// </param>
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to send.
/// </param>
/// <param name="completed">
/// An Action&lt;bool&gt; delegate that references the method(s) called when
@@ -459,10 +451,10 @@ namespace WebSocketSharp.Server
/// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
/// complete successfully; otherwise, <c>false</c>.
/// </param>
protected void Send (Stream stream, int length, bool dispose, Action<bool> completed)
protected void Send (Stream stream, int length, Action<bool> completed)
{
if (_websocket != null)
_websocket.Send (stream, length, dispose, completed);
_websocket.Send (stream, length, completed);
}
/// <summary>

View File

@@ -470,13 +470,9 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to broadcast.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data broadcasted;
/// otherwise, <c>false</c>.
/// </param>
public void Broadcast (Stream stream, int length, bool dispose)
public void Broadcast (Stream stream, int length)
{
Broadcast (stream, length, dispose, null);
Broadcast (stream, length, null);
}
/// <summary>
@@ -492,15 +488,11 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to broadcast.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data broadcasted;
/// otherwise, <c>false</c>.
/// </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, bool dispose, Action completed)
public void Broadcast (Stream stream, int length, Action completed)
{
var msg = _state.CheckIfStarted () ??
stream.CheckIfCanRead () ??
@@ -512,36 +504,32 @@ namespace WebSocketSharp.Server
return;
}
Action<byte []> result = data =>
{
var readLen = data.Length;
if (readLen == 0)
stream.ReadBytesAsync (
length,
data =>
{
_logger.Error ("A data cannot be read from 'stream'.");
return;
}
var len = data.Length;
if (len == 0)
{
_logger.Error ("A data cannot be read from 'stream'.");
return;
}
if (readLen != length)
_logger.Warn (String.Format (
"A data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}",
length,
readLen));
if (len < length)
_logger.Warn (String.Format (
"A data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}",
length,
len));
if (dispose)
stream.Dispose ();
if (readLen <= WebSocket.FragmentLength)
broadcast (Opcode.BINARY, data, completed);
else
broadcast (Opcode.BINARY, new MemoryStream (data), completed);
};
Action<Exception> exception = ex =>
{
_logger.Fatal (ex.ToString ());
};
stream.ReadBytesAsync (length, result, exception);
if (len <= WebSocket.FragmentLength)
broadcast (Opcode.BINARY, data, completed);
else
broadcast (Opcode.BINARY, new MemoryStream (data), completed);
},
ex =>
{
_logger.Fatal (ex.ToString ());
});
}
/// <summary>
@@ -644,13 +632,9 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to broadcast.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data broadcasted;
/// otherwise, <c>false</c>.
/// </param>
public void BroadcastTo (string servicePath, Stream stream, int length, bool dispose)
public void BroadcastTo (string servicePath, Stream stream, int length)
{
BroadcastTo (servicePath, stream, length, dispose, null);
BroadcastTo (servicePath, stream, length, null);
}
/// <summary>
@@ -669,20 +653,16 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to broadcast.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data broadcasted;
/// otherwise, <c>false</c>.
/// </param>
/// <param name="completed">
/// A <see cref="Action"/> delegate that references the method(s) called when
/// the broadcast is complete.
/// </param>
public void BroadcastTo (
string servicePath, Stream stream, int length, bool dispose, Action completed)
string servicePath, Stream stream, int length, Action completed)
{
WebSocketServiceHost host;
if (TryGetServiceHost (servicePath, out host))
host.Sessions.Broadcast (stream, length, dispose, completed);
host.Sessions.Broadcast (stream, length, completed);
}
/// <summary>
@@ -1011,13 +991,9 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to send.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data read;
/// otherwise, <c>false</c>.
/// </param>
public void SendTo (string servicePath, string id, Stream stream, int length, bool dispose)
public void SendTo (string servicePath, string id, Stream stream, int length)
{
SendTo (servicePath, id, stream, length, dispose, null);
SendTo (servicePath, id, stream, length, null);
}
/// <summary>
@@ -1040,10 +1016,6 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to send.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data read;
/// otherwise, <c>false</c>.
/// </param>
/// <param name="completed">
/// An Action&lt;bool&gt; delegate that references the method(s) called when
/// the send is complete.
@@ -1051,11 +1023,11 @@ namespace WebSocketSharp.Server
/// successfully; otherwise, <c>false</c>.
/// </param>
public void SendTo (
string servicePath, string id, Stream stream, int length, bool dispose, Action<bool> completed)
string servicePath, string id, Stream stream, int length, Action<bool> completed)
{
WebSocketServiceHost host;
if (TryGetServiceHost (servicePath, out host))
host.Sessions.SendTo (id, stream, length, dispose, completed);
host.Sessions.SendTo (id, stream, length, completed);
}
/// <summary>

View File

@@ -504,13 +504,9 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to broadcast.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data broadcasted;
/// otherwise, <c>false</c>.
/// </param>
public void Broadcast (Stream stream, int length, bool dispose)
public void Broadcast (Stream stream, int length)
{
Broadcast (stream, length, dispose, null);
Broadcast (stream, length, null);
}
/// <summary>
@@ -526,15 +522,11 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to broadcast.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data broadcasted;
/// otherwise, <c>false</c>.
/// </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, bool dispose, Action completed)
public void Broadcast (Stream stream, int length, Action completed)
{
var msg = _state.CheckIfStarted () ??
stream.CheckIfCanRead () ??
@@ -546,36 +538,32 @@ namespace WebSocketSharp.Server
return;
}
Action<byte []> result = data =>
{
var readLen = data.Length;
if (readLen == 0)
stream.ReadBytesAsync (
length,
data =>
{
_logger.Error ("A data cannot be read from 'stream'.");
return;
}
var len = data.Length;
if (len == 0)
{
_logger.Error ("A data cannot be read from 'stream'.");
return;
}
if (readLen != length)
_logger.Warn (String.Format (
"A data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}",
length,
readLen));
if (len < length)
_logger.Warn (String.Format (
"A data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}",
length,
len));
if (dispose)
stream.Dispose ();
if (readLen <= WebSocket.FragmentLength)
Broadcast (Opcode.BINARY, data, completed);
else
Broadcast (Opcode.BINARY, new MemoryStream (data), completed);
};
Action<Exception> exception = ex =>
{
_logger.Fatal (ex.ToString ());
};
stream.ReadBytesAsync (length, result, exception);
if (len <= WebSocket.FragmentLength)
Broadcast (Opcode.BINARY, data, completed);
else
Broadcast (Opcode.BINARY, new MemoryStream (data), completed);
},
ex =>
{
_logger.Fatal (ex.ToString ());
});
}
/// <summary>
@@ -826,13 +814,9 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to send.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data read;
/// otherwise, <c>false</c>.
/// </param>
public void SendTo (string id, Stream stream, int length, bool dispose)
public void SendTo (string id, Stream stream, int length)
{
SendTo (id, stream, length, dispose, null);
SendTo (id, stream, length, null);
}
/// <summary>
@@ -852,10 +836,6 @@ namespace WebSocketSharp.Server
/// <param name="length">
/// An <see cref="int"/> that contains the number of bytes to send.
/// </param>
/// <param name="dispose">
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data read;
/// otherwise, <c>false</c>.
/// </param>
/// <param name="completed">
/// An Action&lt;bool&gt; delegate that references the method(s) called when
/// the send is complete.
@@ -863,11 +843,11 @@ namespace WebSocketSharp.Server
/// successfully; otherwise, <c>false</c>.
/// </param>
public void SendTo (
string id, Stream stream, int length, bool dispose, Action<bool> completed)
string id, Stream stream, int length, Action<bool> completed)
{
IWebSocketSession session;
if (TryGetSession (id, out session))
session.Context.WebSocket.Send (stream, length, dispose, completed);
session.Context.WebSocket.Send (stream, length, completed);
}
/// <summary>