[Modify] Polish it
This commit is contained in:
parent
7d520184c8
commit
29e0d3607a
@ -426,8 +426,7 @@ Extended Payload Length: {7}
|
|||||||
private static WebSocketFrame processHeader (byte[] header)
|
private static WebSocketFrame processHeader (byte[] header)
|
||||||
{
|
{
|
||||||
if (header.Length != 2)
|
if (header.Length != 2)
|
||||||
throw new WebSocketException (
|
throw new WebSocketException ("The header of a frame cannot be read from the stream.");
|
||||||
"The header part of a frame cannot be read from the data source.");
|
|
||||||
|
|
||||||
// FIN
|
// FIN
|
||||||
var fin = (header[0] & 0x80) == 0x80 ? Fin.Final : Fin.More;
|
var fin = (header[0] & 0x80) == 0x80 ? Fin.Final : Fin.More;
|
||||||
@ -450,7 +449,6 @@ Extended Payload Length: {7}
|
|||||||
// Payload Length
|
// Payload Length
|
||||||
var payloadLen = (byte) (header[1] & 0x7f);
|
var payloadLen = (byte) (header[1] & 0x7f);
|
||||||
|
|
||||||
// Check if valid header.
|
|
||||||
var err = !opcode.IsSupported ()
|
var err = !opcode.IsSupported ()
|
||||||
? "An unsupported opcode."
|
? "An unsupported opcode."
|
||||||
: !opcode.IsData () && rsv1 == Rsv.On
|
: !opcode.IsData () && rsv1 == Rsv.On
|
||||||
@ -487,7 +485,7 @@ Extended Payload Length: {7}
|
|||||||
var bytes = stream.ReadBytes (len);
|
var bytes = stream.ReadBytes (len);
|
||||||
if (bytes.Length != len)
|
if (bytes.Length != len)
|
||||||
throw new WebSocketException (
|
throw new WebSocketException (
|
||||||
"The 'Extended Payload Length' of a frame cannot be read from the data source.");
|
"The extended payload length of a frame cannot be read from the stream.");
|
||||||
|
|
||||||
frame._extPayloadLength = bytes;
|
frame._extPayloadLength = bytes;
|
||||||
return frame;
|
return frame;
|
||||||
@ -512,7 +510,7 @@ Extended Payload Length: {7}
|
|||||||
bytes => {
|
bytes => {
|
||||||
if (bytes.Length != len)
|
if (bytes.Length != len)
|
||||||
throw new WebSocketException (
|
throw new WebSocketException (
|
||||||
"The 'Extended Payload Length' of a frame cannot be read from the data source.");
|
"The extended payload length of a frame cannot be read from the stream.");
|
||||||
|
|
||||||
frame._extPayloadLength = bytes;
|
frame._extPayloadLength = bytes;
|
||||||
completed (frame);
|
completed (frame);
|
||||||
@ -541,8 +539,7 @@ Extended Payload Length: {7}
|
|||||||
|
|
||||||
var bytes = stream.ReadBytes (len);
|
var bytes = stream.ReadBytes (len);
|
||||||
if (bytes.Length != len)
|
if (bytes.Length != len)
|
||||||
throw new WebSocketException (
|
throw new WebSocketException ("The masking key of a frame cannot be read from the stream.");
|
||||||
"The 'Masking Key' of a frame cannot be read from the data source.");
|
|
||||||
|
|
||||||
frame._maskingKey = bytes;
|
frame._maskingKey = bytes;
|
||||||
return frame;
|
return frame;
|
||||||
@ -567,7 +564,7 @@ Extended Payload Length: {7}
|
|||||||
bytes => {
|
bytes => {
|
||||||
if (bytes.Length != len)
|
if (bytes.Length != len)
|
||||||
throw new WebSocketException (
|
throw new WebSocketException (
|
||||||
"The 'Masking Key' of a frame cannot be read from the data source.");
|
"The masking key of a frame cannot be read from the stream.");
|
||||||
|
|
||||||
frame._maskingKey = bytes;
|
frame._maskingKey = bytes;
|
||||||
completed (frame);
|
completed (frame);
|
||||||
@ -583,11 +580,8 @@ Extended Payload Length: {7}
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if allowable length.
|
|
||||||
if (len > PayloadData.MaxLength)
|
if (len > PayloadData.MaxLength)
|
||||||
throw new WebSocketException (
|
throw new WebSocketException (CloseStatusCode.TooBig, "A frame has a long payload length.");
|
||||||
CloseStatusCode.TooBig,
|
|
||||||
"The length of 'Payload Data' of a frame is greater than the allowable max length.");
|
|
||||||
|
|
||||||
var llen = (long) len;
|
var llen = (long) len;
|
||||||
var bytes = frame._payloadLength < 127
|
var bytes = frame._payloadLength < 127
|
||||||
@ -596,7 +590,7 @@ Extended Payload Length: {7}
|
|||||||
|
|
||||||
if (bytes.LongLength != llen)
|
if (bytes.LongLength != llen)
|
||||||
throw new WebSocketException (
|
throw new WebSocketException (
|
||||||
"The 'Payload Data' of a frame cannot be read from the data source.");
|
"The payload data of a frame cannot be read from the stream.");
|
||||||
|
|
||||||
frame._payloadData = new PayloadData (bytes, llen);
|
frame._payloadData = new PayloadData (bytes, llen);
|
||||||
return frame;
|
return frame;
|
||||||
@ -616,17 +610,14 @@ Extended Payload Length: {7}
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if allowable length.
|
|
||||||
if (len > PayloadData.MaxLength)
|
if (len > PayloadData.MaxLength)
|
||||||
throw new WebSocketException (
|
throw new WebSocketException (CloseStatusCode.TooBig, "A frame has a long payload length.");
|
||||||
CloseStatusCode.TooBig,
|
|
||||||
"The length of 'Payload Data' of a frame is greater than the allowable max length.");
|
|
||||||
|
|
||||||
var llen = (long) len;
|
var llen = (long) len;
|
||||||
Action<byte[]> compl = bytes => {
|
Action<byte[]> compl = bytes => {
|
||||||
if (bytes.LongLength != llen)
|
if (bytes.LongLength != llen)
|
||||||
throw new WebSocketException (
|
throw new WebSocketException (
|
||||||
"The 'Payload Data' of a frame cannot be read from the data source.");
|
"The payload data of a frame cannot be read from the stream.");
|
||||||
|
|
||||||
frame._payloadData = new PayloadData (bytes, llen);
|
frame._payloadData = new PayloadData (bytes, llen);
|
||||||
completed (frame);
|
completed (frame);
|
||||||
|
Loading…
Reference in New Issue
Block a user