From 39add76329f8d032618d51d417edb61d6509c4af Mon Sep 17 00:00:00 2001 From: sta Date: Fri, 16 Oct 2015 11:26:36 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/Ext.cs | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index e004217b..e9e99b32 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -942,31 +942,20 @@ namespace WebSocketSharp this Stream stream, byte[] bytes, int bufferLength, Action completed, Action error) { var input = new MemoryStream (bytes); - var buff = new byte[bufferLength]; + input.CopyToAsync ( + stream, + bufferLength, + () => { + if (completed != null) + completed (); - AsyncCallback callback = null; - callback = ar => { - try { - var nread = input.EndRead (ar); - if (nread <= 0) { - if (completed != null) - completed (); - - input.Dispose (); - return; - } - - stream.Write (buff, 0, nread); - input.BeginRead (buff, 0, bufferLength, callback, null); - } - catch (Exception ex) { + input.Dispose (); + }, + ex => { input.Dispose (); if (error != null) error (ex); - } - }; - - input.BeginRead (buff, 0, bufferLength, callback, null); + }); } #endregion