From e65bd0aaee718bb0095e391b9c27e747350c0a38 Mon Sep 17 00:00:00 2001 From: sta Date: Wed, 23 Nov 2016 17:21:40 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/WebSocket.cs | 39 ++++++++++++------------------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index ae9837eb..a923d5a3 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -2907,35 +2907,22 @@ namespace WebSocketSharp if (length < 1) throw new ArgumentException ("Less than 1.", "length"); - stream.ReadBytesAsync ( - length, - data => { - var len = data.Length; - if (len == 0) { - _logger.Error ("The data cannot be read from 'stream'."); - error ("An error has occurred in sending data.", null); + var bytes = stream.ReadBytes (length); - return; - } + var len = bytes.Length; + if (len == 0) + throw new ArgumentException ("No data could be read.", "stream"); - if (len < length) - _logger.Warn ( - String.Format ( - "The length of the data is less than 'length':\n expected: {0}\n actual: {1}", - length, - len - ) - ); + if (len < length) { + _logger.Warn ( + String.Format ( + "Only {0} byte(s) of data could be read from the specified stream.", + len + ) + ); + } - var sent = send (Opcode.Binary, new MemoryStream (data)); - if (completed != null) - completed (sent); - }, - ex => { - _logger.Error (ex.ToString ()); - error ("An exception has occurred while sending data.", ex); - } - ); + sendAsync (Opcode.Binary, new MemoryStream (bytes), completed); } ///