diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs
index 83e518c3..63c23024 100644
--- a/websocket-sharp/Ext.cs
+++ b/websocket-sharp/Ext.cs
@@ -376,7 +376,7 @@ namespace WebSocketSharp
internal static void CopyTo (this Stream source, Stream destination)
{
- var buffLen = 256;
+ var buffLen = 1024;
var buff = new byte[buffLen];
var nread = 0;
while ((nread = source.Read (buff, 0, buffLen)) > 0)
@@ -1761,7 +1761,7 @@ namespace WebSocketSharp
}
///
- /// Writes the specified data with the specified
+ /// Writes and sends the specified data with the specified
/// .
///
///
@@ -1772,20 +1772,37 @@ namespace WebSocketSharp
/// An array of that represents the content data to send.
///
///
- /// is .
+ ///
+ /// is .
+ ///
+ ///
+ /// -or-
+ ///
+ ///
+ /// is .
+ ///
///
public static void WriteContent (this HttpListenerResponse response, byte[] content)
{
if (response == null)
throw new ArgumentNullException ("response");
- var len = 0L;
- if (content == null || (len = content.LongLength) == 0)
+ if (content == null)
+ throw new ArgumentNullException ("content");
+
+ var len = content.LongLength;
+ if (len == 0) {
+ response.Close ();
return;
+ }
- var output = response.OutputStream;
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 ();
}