Refactored a few for ResponseStream.cs
This commit is contained in:
parent
854005660b
commit
849c964102
@ -111,6 +111,22 @@ namespace WebSocketSharp.Net
|
|||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
|
||||||
|
private static void checkWriteParameters (byte[] buffer, int offset, int count)
|
||||||
|
{
|
||||||
|
if (buffer == null)
|
||||||
|
throw new ArgumentNullException ("buffer");
|
||||||
|
|
||||||
|
if (offset < 0)
|
||||||
|
throw new ArgumentOutOfRangeException ("offset", "A negative value.");
|
||||||
|
|
||||||
|
if (count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException ("count", "A negative value.");
|
||||||
|
|
||||||
|
if (offset + count > buffer.Length)
|
||||||
|
throw new ArgumentException (
|
||||||
|
"The sum of 'offset' and 'count' is greater than 'buffer' length.");
|
||||||
|
}
|
||||||
|
|
||||||
private static byte[] getChunkSizeBytes (int size, bool final)
|
private static byte[] getChunkSizeBytes (int size, bool final)
|
||||||
{
|
{
|
||||||
return Encoding.ASCII.GetBytes (String.Format ("{0:x}\r\n{1}", size, final ? "\r\n" : ""));
|
return Encoding.ASCII.GetBytes (String.Format ("{0:x}\r\n{1}", size, final ? "\r\n" : ""));
|
||||||
@ -161,6 +177,10 @@ namespace WebSocketSharp.Net
|
|||||||
if (_disposed)
|
if (_disposed)
|
||||||
throw new ObjectDisposedException (GetType ().ToString ());
|
throw new ObjectDisposedException (GetType ().ToString ());
|
||||||
|
|
||||||
|
checkWriteParameters (buffer, offset, count);
|
||||||
|
if (count == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
var headers = getHeaders (false);
|
var headers = getHeaders (false);
|
||||||
var chunked = _response.SendChunked;
|
var chunked = _response.SendChunked;
|
||||||
if (headers != null) {
|
if (headers != null) {
|
||||||
@ -228,6 +248,9 @@ namespace WebSocketSharp.Net
|
|||||||
if (_disposed)
|
if (_disposed)
|
||||||
throw new ObjectDisposedException (GetType ().ToString ());
|
throw new ObjectDisposedException (GetType ().ToString ());
|
||||||
|
|
||||||
|
if (asyncResult == null)
|
||||||
|
throw new ArgumentNullException ("asyncResult");
|
||||||
|
|
||||||
Action<IAsyncResult> endWrite = ares => {
|
Action<IAsyncResult> endWrite = ares => {
|
||||||
_stream.EndWrite (ares);
|
_stream.EndWrite (ares);
|
||||||
if (_response.SendChunked)
|
if (_response.SendChunked)
|
||||||
@ -270,6 +293,10 @@ namespace WebSocketSharp.Net
|
|||||||
if (_disposed)
|
if (_disposed)
|
||||||
throw new ObjectDisposedException (GetType ().ToString ());
|
throw new ObjectDisposedException (GetType ().ToString ());
|
||||||
|
|
||||||
|
checkWriteParameters (buffer, offset, count);
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
var headers = getHeaders (false);
|
var headers = getHeaders (false);
|
||||||
var chunked = _response.SendChunked;
|
var chunked = _response.SendChunked;
|
||||||
if (headers != null) {
|
if (headers != null) {
|
||||||
@ -293,9 +320,7 @@ namespace WebSocketSharp.Net
|
|||||||
InternalWrite (size, 0, size.Length);
|
InternalWrite (size, 0, size.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0)
|
|
||||||
InternalWrite (buffer, offset, count);
|
InternalWrite (buffer, offset, count);
|
||||||
|
|
||||||
if (chunked)
|
if (chunked)
|
||||||
InternalWrite (_crlf, 0, 2);
|
InternalWrite (_crlf, 0, 2);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user