From 9113555a54a54197dec2c1a9a672a1e7d1015d35 Mon Sep 17 00:00:00 2001 From: sta Date: Sat, 23 May 2015 16:55:40 +0900 Subject: [PATCH] Refactored a few for HttpConnection.cs --- websocket-sharp/Net/HttpConnection.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/websocket-sharp/Net/HttpConnection.cs b/websocket-sharp/Net/HttpConnection.cs index b7191322..708489a1 100644 --- a/websocket-sharp/Net/HttpConnection.cs +++ b/websocket-sharp/Net/HttpConnection.cs @@ -327,10 +327,13 @@ namespace WebSocketSharp.Net // false -> Need more input. private bool processInput (byte[] data, int length) { + if (_currentLine == null) + _currentLine = new StringBuilder (); + var nread = 0; try { string line; - while ((line = readLineFrom (data, _position, length - _position, ref nread)) != null) { + while ((line = readLineFrom (data, _position, length, out nread)) != null) { _position += nread; if (line.Length == 0) { if (_inputState == InputState.RequestLine) @@ -361,14 +364,10 @@ namespace WebSocketSharp.Net return false; } - private string readLineFrom (byte[] buffer, int offset, int count, ref int read) + private string readLineFrom (byte[] buffer, int offset, int length, out int read) { - if (_currentLine == null) - _currentLine = new StringBuilder (); - - var last = offset + count; read = 0; - for (var i = offset; i < last && _lineState != LineState.Lf; i++) { + for (var i = offset; i < length && _lineState != LineState.Lf; i++) { read++; var b = buffer[i]; if (b == 13)