Refactored a few for Ext.cs

This commit is contained in:
sta 2015-05-28 20:03:43 +09:00
parent f947beb12f
commit 3c8b8210ac

View File

@ -376,7 +376,7 @@ namespace WebSocketSharp
internal static void CopyTo (this Stream source, Stream destination) internal static void CopyTo (this Stream source, Stream destination)
{ {
var buffLen = 256; var buffLen = 1024;
var buff = new byte[buffLen]; var buff = new byte[buffLen];
var nread = 0; var nread = 0;
while ((nread = source.Read (buff, 0, buffLen)) > 0) while ((nread = source.Read (buff, 0, buffLen)) > 0)
@ -1761,7 +1761,7 @@ namespace WebSocketSharp
} }
/// <summary> /// <summary>
/// Writes the specified <paramref name="content"/> data with the specified /// Writes and sends the specified <paramref name="content"/> data with the specified
/// <see cref="HttpListenerResponse"/>. /// <see cref="HttpListenerResponse"/>.
/// </summary> /// </summary>
/// <param name="response"> /// <param name="response">
@ -1772,20 +1772,37 @@ namespace WebSocketSharp
/// An array of <see cref="byte"/> that represents the content data to send. /// An array of <see cref="byte"/> that represents the content data to send.
/// </param> /// </param>
/// <exception cref="ArgumentNullException"> /// <exception cref="ArgumentNullException">
/// <paramref name="response"/> is <see langword="null"/>. /// <para>
/// <paramref name="response"/> is <see langword="null"/>.
/// </para>
/// <para>
/// -or-
/// </para>
/// <para>
/// <paramref name="content"/> is <see langword="null"/>.
/// </para>
/// </exception> /// </exception>
public static void WriteContent (this HttpListenerResponse response, byte[] content) public static void WriteContent (this HttpListenerResponse response, byte[] content)
{ {
if (response == null) if (response == null)
throw new ArgumentNullException ("response"); throw new ArgumentNullException ("response");
var len = 0L; if (content == null)
if (content == null || (len = content.LongLength) == 0) throw new ArgumentNullException ("content");
return;
var len = content.LongLength;
if (len == 0) {
response.Close ();
return;
}
var output = response.OutputStream;
response.ContentLength64 = len; response.ContentLength64 = len;
output.WriteBytes (content); var output = response.OutputStream;
if (len <= Int32.MaxValue)
output.Write (content, 0, (int) len);
else
output.WriteBytes (content);
output.Close (); output.Close ();
} }