From 3c8b8210acf05696febba15ff6bc1b523dad58c2 Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 28 May 2015 20:03:43 +0900 Subject: [PATCH] Refactored a few for Ext.cs --- websocket-sharp/Ext.cs | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) 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) - return; + 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 (); }