[Modify] Polish it

This commit is contained in:
sta 2016-11-20 16:36:22 +09:00
parent 1ae31c6479
commit 5b8239d9bd

View File

@ -1575,9 +1575,6 @@ namespace WebSocketSharp
private bool send (Opcode opcode, Stream stream, bool compressed) private bool send (Opcode opcode, Stream stream, bool compressed)
{ {
var len = stream.Length; var len = stream.Length;
/* Not fragmented */
if (len == 0) if (len == 0)
return send (Fin.Final, opcode, EmptyBytes, compressed); return send (Fin.Final, opcode, EmptyBytes, compressed);
@ -1587,27 +1584,34 @@ namespace WebSocketSharp
byte[] buff = null; byte[] buff = null;
if (quo == 0) { if (quo == 0) {
buff = new byte[rem]; buff = new byte[rem];
return stream.Read (buff, 0, rem) == rem && return stream.Read (buff, 0, rem) == rem
send (Fin.Final, opcode, buff, compressed); && send (Fin.Final, opcode, buff, compressed);
} }
buff = new byte[FragmentLength]; if (quo == 1 && rem == 0) {
if (quo == 1 && rem == 0) buff = new byte[FragmentLength];
return stream.Read (buff, 0, FragmentLength) == FragmentLength && return stream.Read (buff, 0, FragmentLength) == FragmentLength
send (Fin.Final, opcode, buff, compressed); && send (Fin.Final, opcode, buff, compressed);
}
/* Send fragmented */ /* Send fragments */
// Begin // Begin
if (stream.Read (buff, 0, FragmentLength) != FragmentLength || buff = new byte[FragmentLength];
!send (Fin.More, opcode, buff, compressed)) var sent = stream.Read (buff, 0, FragmentLength) == FragmentLength
&& send (Fin.More, opcode, buff, compressed);
if (!sent)
return false; return false;
var n = rem == 0 ? quo - 2 : quo - 1; var n = rem == 0 ? quo - 2 : quo - 1;
for (long i = 0; i < n; i++) for (long i = 0; i < n; i++) {
if (stream.Read (buff, 0, FragmentLength) != FragmentLength || sent = stream.Read (buff, 0, FragmentLength) == FragmentLength
!send (Fin.More, Opcode.Cont, buff, compressed)) && send (Fin.More, Opcode.Cont, buff, compressed);
if (!sent)
return false; return false;
}
// End // End
if (rem == 0) if (rem == 0)
@ -1615,7 +1619,8 @@ namespace WebSocketSharp
else else
buff = new byte[rem]; buff = new byte[rem];
return stream.Read (buff, 0, rem) == rem && send (Fin.Final, Opcode.Cont, buff, compressed); return stream.Read (buff, 0, rem) == rem
&& send (Fin.Final, Opcode.Cont, buff, compressed);
} }
private bool send (Fin fin, Opcode opcode, byte[] data, bool compressed) private bool send (Fin fin, Opcode opcode, byte[] data, bool compressed)