Renamed WsFrame.cs to WebSocketFrame.cs
This commit is contained in:
parent
bb45e3b479
commit
c20f4804c7
@ -317,9 +317,8 @@ namespace WebSocketSharp.Server
|
|||||||
|
|
||||||
var payload = new PayloadData (data);
|
var payload = new PayloadData (data);
|
||||||
var args = new CloseEventArgs (payload);
|
var args = new CloseEventArgs (payload);
|
||||||
var frameAsBytes = send
|
var frameAsBytes =
|
||||||
? WsFrame.CreateCloseFrame (Mask.Unmask, payload).ToByteArray ()
|
send ? WebSocketFrame.CreateCloseFrame (Mask.Unmask, payload).ToByteArray () : null;
|
||||||
: null;
|
|
||||||
|
|
||||||
foreach (var host in _hosts.Values)
|
foreach (var host in _hosts.Values)
|
||||||
host.Sessions.Stop (args, frameAsBytes);
|
host.Sessions.Stop (args, frameAsBytes);
|
||||||
@ -517,7 +516,7 @@ namespace WebSocketSharp.Server
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return broadping (WsFrame.EmptyUnmaskPingData, 1000);
|
return broadping (WebSocketFrame.EmptyUnmaskPingData, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -547,7 +546,7 @@ namespace WebSocketSharp.Server
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return broadping (WsFrame.CreatePingFrame (Mask.Unmask, data).ToByteArray (), 1000);
|
return broadping (WebSocketFrame.CreatePingFrame (Mask.Unmask, data).ToByteArray (), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -110,7 +110,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// </value>
|
/// </value>
|
||||||
public IEnumerable<string> ActiveIDs {
|
public IEnumerable<string> ActiveIDs {
|
||||||
get {
|
get {
|
||||||
foreach (var result in Broadping (WsFrame.EmptyUnmaskPingData, 1000))
|
foreach (var result in Broadping (WebSocketFrame.EmptyUnmaskPingData, 1000))
|
||||||
if (result.Value)
|
if (result.Value)
|
||||||
yield return result.Key;
|
yield return result.Key;
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// </value>
|
/// </value>
|
||||||
public IEnumerable<string> InactiveIDs {
|
public IEnumerable<string> InactiveIDs {
|
||||||
get {
|
get {
|
||||||
foreach (var result in Broadping (WsFrame.EmptyUnmaskPingData, 1000))
|
foreach (var result in Broadping (WebSocketFrame.EmptyUnmaskPingData, 1000))
|
||||||
if (!result.Value)
|
if (!result.Value)
|
||||||
yield return result.Key;
|
yield return result.Key;
|
||||||
}
|
}
|
||||||
@ -367,9 +367,8 @@ namespace WebSocketSharp.Server
|
|||||||
{
|
{
|
||||||
var payload = new PayloadData (data);
|
var payload = new PayloadData (data);
|
||||||
var args = new CloseEventArgs (payload);
|
var args = new CloseEventArgs (payload);
|
||||||
var frameAsBytes = send
|
var frameAsBytes =
|
||||||
? WsFrame.CreateCloseFrame (Mask.Unmask, payload).ToByteArray ()
|
send ? WebSocketFrame.CreateCloseFrame (Mask.Unmask, payload).ToByteArray () : null;
|
||||||
: null;
|
|
||||||
|
|
||||||
Stop (args, frameAsBytes);
|
Stop (args, frameAsBytes);
|
||||||
}
|
}
|
||||||
@ -556,7 +555,7 @@ namespace WebSocketSharp.Server
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Broadping (WsFrame.EmptyUnmaskPingData, 1000);
|
return Broadping (WebSocketFrame.EmptyUnmaskPingData, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -584,8 +583,7 @@ namespace WebSocketSharp.Server
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Broadping (
|
return Broadping (WebSocketFrame.CreatePingFrame (Mask.Unmask, data).ToByteArray (), 1000);
|
||||||
WsFrame.CreatePingFrame (Mask.Unmask, data).ToByteArray (), 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -491,7 +491,7 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
|
||||||
private bool acceptCloseFrame (WsFrame frame)
|
private bool acceptCloseFrame (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
var payload = frame.PayloadData;
|
var payload = frame.PayloadData;
|
||||||
close (payload, !payload.ContainsReservedCloseStatusCode, false);
|
close (payload, !payload.ContainsReservedCloseStatusCode, false);
|
||||||
@ -499,7 +499,7 @@ namespace WebSocketSharp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool acceptDataFrame (WsFrame frame)
|
private bool acceptDataFrame (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
var e = frame.IsCompressed
|
var e = frame.IsCompressed
|
||||||
? new MessageEventArgs (
|
? new MessageEventArgs (
|
||||||
@ -532,14 +532,14 @@ namespace WebSocketSharp
|
|||||||
close (code, reason ?? code.GetMessage (), false);
|
close (code, reason ?? code.GetMessage (), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool acceptFragmentedFrame (WsFrame frame)
|
private bool acceptFragmentedFrame (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
return frame.IsContinuation // Not first fragment
|
return frame.IsContinuation // Not first fragment
|
||||||
? true
|
? true
|
||||||
: acceptFragments (frame);
|
: acceptFragments (frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool acceptFragments (WsFrame first)
|
private bool acceptFragments (WebSocketFrame first)
|
||||||
{
|
{
|
||||||
using (var concatenated = new MemoryStream ()) {
|
using (var concatenated = new MemoryStream ()) {
|
||||||
concatenated.WriteBytes (first.PayloadData.ApplicationData);
|
concatenated.WriteBytes (first.PayloadData.ApplicationData);
|
||||||
@ -560,7 +560,7 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool acceptFrame (WsFrame frame)
|
private bool acceptFrame (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
return frame.IsCompressed && _compression == CompressionMethod.None
|
return frame.IsCompressed && _compression == CompressionMethod.None
|
||||||
? acceptUnsupportedFrame (
|
? acceptUnsupportedFrame (
|
||||||
@ -607,16 +607,16 @@ namespace WebSocketSharp
|
|||||||
return send (createHandshakeResponse ());
|
return send (createHandshakeResponse ());
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool acceptPingFrame (WsFrame frame)
|
private bool acceptPingFrame (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
var mask = _client ? Mask.Mask : Mask.Unmask;
|
var mask = _client ? Mask.Mask : Mask.Unmask;
|
||||||
if (send (WsFrame.CreatePongFrame (mask, frame.PayloadData)))
|
if (send (WebSocketFrame.CreatePongFrame (mask, frame.PayloadData)))
|
||||||
_logger.Trace ("Returned a Pong.");
|
_logger.Trace ("Returned a Pong.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool acceptPongFrame (WsFrame frame)
|
private bool acceptPongFrame (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
_receivePong.Set ();
|
_receivePong.Set ();
|
||||||
_logger.Trace ("Received a Pong.");
|
_logger.Trace ("Received a Pong.");
|
||||||
@ -652,7 +652,7 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool acceptUnsupportedFrame (WsFrame frame, CloseStatusCode code, string reason)
|
private bool acceptUnsupportedFrame (WebSocketFrame frame, CloseStatusCode code, string reason)
|
||||||
{
|
{
|
||||||
_logger.Debug ("Unsupported frame:\n" + frame.PrintToString (false));
|
_logger.Debug ("Unsupported frame:\n" + frame.PrintToString (false));
|
||||||
acceptException (new WebSocketException (code, reason), null);
|
acceptException (new WebSocketException (code, reason), null);
|
||||||
@ -733,11 +733,11 @@ namespace WebSocketSharp
|
|||||||
e.WasClean =
|
e.WasClean =
|
||||||
_client
|
_client
|
||||||
? closeHandshake (
|
? closeHandshake (
|
||||||
send ? WsFrame.CreateCloseFrame (Mask.Mask, payload).ToByteArray () : null,
|
send ? WebSocketFrame.CreateCloseFrame (Mask.Mask, payload).ToByteArray () : null,
|
||||||
wait ? 5000 : 0,
|
wait ? 5000 : 0,
|
||||||
closeClientResources)
|
closeClientResources)
|
||||||
: closeHandshake (
|
: closeHandshake (
|
||||||
send ? WsFrame.CreateCloseFrame (Mask.Unmask, payload).ToByteArray () : null,
|
send ? WebSocketFrame.CreateCloseFrame (Mask.Unmask, payload).ToByteArray () : null,
|
||||||
wait ? 1000 : 0,
|
wait ? 1000 : 0,
|
||||||
closeServerResources);
|
closeServerResources);
|
||||||
|
|
||||||
@ -1085,7 +1085,7 @@ namespace WebSocketSharp
|
|||||||
return _stream.WriteHandshake (response);
|
return _stream.WriteHandshake (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool send (WsFrame frame)
|
private bool send (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
lock (_forConn) {
|
lock (_forConn) {
|
||||||
if (_readyState != WebSocketState.Open) {
|
if (_readyState != WebSocketState.Open) {
|
||||||
@ -1109,7 +1109,7 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
var mask = _client ? Mask.Mask : Mask.Unmask;
|
var mask = _client ? Mask.Mask : Mask.Unmask;
|
||||||
sent = send (WsFrame.CreateFrame (Fin.Final, opcode, mask, data, compressed));
|
sent = send (WebSocketFrame.CreateFrame (Fin.Final, opcode, mask, data, compressed));
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
_logger.Fatal (ex.ToString ());
|
_logger.Fatal (ex.ToString ());
|
||||||
@ -1203,20 +1203,20 @@ namespace WebSocketSharp
|
|||||||
if (quo == 0) {
|
if (quo == 0) {
|
||||||
buffer = new byte [rem];
|
buffer = new byte [rem];
|
||||||
return stream.Read (buffer, 0, rem) == rem &&
|
return stream.Read (buffer, 0, rem) == rem &&
|
||||||
send (WsFrame.CreateFrame (Fin.Final, opcode, mask, buffer, compressed));
|
send (WebSocketFrame.CreateFrame (Fin.Final, opcode, mask, buffer, compressed));
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = new byte [FragmentLength];
|
buffer = new byte [FragmentLength];
|
||||||
|
|
||||||
// First
|
// First
|
||||||
if (stream.Read (buffer, 0, FragmentLength) != FragmentLength ||
|
if (stream.Read (buffer, 0, FragmentLength) != FragmentLength ||
|
||||||
!send (WsFrame.CreateFrame (Fin.More, opcode, mask, buffer, compressed)))
|
!send (WebSocketFrame.CreateFrame (Fin.More, opcode, mask, buffer, compressed)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Mid
|
// Mid
|
||||||
for (long i = 0; i < times; i++) {
|
for (long i = 0; i < times; i++) {
|
||||||
if (stream.Read (buffer, 0, FragmentLength) != FragmentLength ||
|
if (stream.Read (buffer, 0, FragmentLength) != FragmentLength ||
|
||||||
!send (WsFrame.CreateFrame (Fin.More, Opcode.Cont, mask, buffer, compressed)))
|
!send (WebSocketFrame.CreateFrame (Fin.More, Opcode.Cont, mask, buffer, compressed)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1226,7 +1226,7 @@ namespace WebSocketSharp
|
|||||||
buffer = new byte [tmpLen = rem];
|
buffer = new byte [tmpLen = rem];
|
||||||
|
|
||||||
return stream.Read (buffer, 0, tmpLen) == tmpLen &&
|
return stream.Read (buffer, 0, tmpLen) == tmpLen &&
|
||||||
send (WsFrame.CreateFrame (Fin.Final, Opcode.Cont, mask, buffer, compressed));
|
send (WebSocketFrame.CreateFrame (Fin.Final, Opcode.Cont, mask, buffer, compressed));
|
||||||
}
|
}
|
||||||
|
|
||||||
// As client
|
// As client
|
||||||
@ -1475,7 +1475,7 @@ namespace WebSocketSharp
|
|||||||
try {
|
try {
|
||||||
byte [] cached;
|
byte [] cached;
|
||||||
if (!cache.TryGetValue (_compression, out cached)) {
|
if (!cache.TryGetValue (_compression, out cached)) {
|
||||||
cached = WsFrame.CreateFrame (
|
cached = WebSocketFrame.CreateFrame (
|
||||||
Fin.Final,
|
Fin.Final,
|
||||||
opcode,
|
opcode,
|
||||||
Mask.Unmask,
|
Mask.Unmask,
|
||||||
@ -1819,8 +1819,8 @@ namespace WebSocketSharp
|
|||||||
public bool Ping ()
|
public bool Ping ()
|
||||||
{
|
{
|
||||||
return _client
|
return _client
|
||||||
? Ping (WsFrame.CreatePingFrame (Mask.Mask).ToByteArray (), 5000)
|
? Ping (WebSocketFrame.CreatePingFrame (Mask.Mask).ToByteArray (), 5000)
|
||||||
: Ping (WsFrame.EmptyUnmaskPingData, 1000);
|
: Ping (WebSocketFrame.EmptyUnmaskPingData, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -1848,8 +1848,8 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
return _client
|
return _client
|
||||||
? Ping (WsFrame.CreatePingFrame (Mask.Mask, data).ToByteArray (), 5000)
|
? Ping (WebSocketFrame.CreatePingFrame (Mask.Mask, data).ToByteArray (), 5000)
|
||||||
: Ping (WsFrame.CreatePingFrame (Mask.Unmask, data).ToByteArray (), 1000);
|
: Ping (WebSocketFrame.CreatePingFrame (Mask.Unmask, data).ToByteArray (), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#region License
|
#region License
|
||||||
/*
|
/*
|
||||||
* WsFrame.cs
|
* WebSocketFrame.cs
|
||||||
*
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
*
|
*
|
||||||
@ -34,7 +34,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace WebSocketSharp
|
namespace WebSocketSharp
|
||||||
{
|
{
|
||||||
internal class WsFrame : IEnumerable<byte>
|
internal class WebSocketFrame : IEnumerable<byte>
|
||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
#region Static Constructor
|
#region Static Constructor
|
||||||
|
|
||||||
static WsFrame ()
|
static WebSocketFrame ()
|
||||||
{
|
{
|
||||||
EmptyUnmaskPingData = CreatePingFrame (Mask.Unmask).ToByteArray ();
|
EmptyUnmaskPingData = CreatePingFrame (Mask.Unmask).ToByteArray ();
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
#region Private Constructors
|
#region Private Constructors
|
||||||
|
|
||||||
private WsFrame ()
|
private WebSocketFrame ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,22 +76,22 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
#region Public Constructors
|
#region Public Constructors
|
||||||
|
|
||||||
public WsFrame (Opcode opcode, PayloadData payload)
|
public WebSocketFrame (Opcode opcode, PayloadData payload)
|
||||||
: this (Fin.Final, opcode, Mask.Mask, payload, false)
|
: this (Fin.Final, opcode, Mask.Mask, payload, false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public WsFrame (Opcode opcode, Mask mask, PayloadData payload)
|
public WebSocketFrame (Opcode opcode, Mask mask, PayloadData payload)
|
||||||
: this (Fin.Final, opcode, mask, payload, false)
|
: this (Fin.Final, opcode, mask, payload, false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public WsFrame (Fin fin, Opcode opcode, Mask mask, PayloadData payload)
|
public WebSocketFrame (Fin fin, Opcode opcode, Mask mask, PayloadData payload)
|
||||||
: this (fin, opcode, mask, payload, false)
|
: this (fin, opcode, mask, payload, false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public WsFrame (Fin fin, Opcode opcode, Mask mask, PayloadData payload, bool compressed)
|
public WebSocketFrame (Fin fin, Opcode opcode, Mask mask, PayloadData payload, bool compressed)
|
||||||
{
|
{
|
||||||
_fin = fin;
|
_fin = fin;
|
||||||
_rsv1 = isData (opcode) && compressed ? Rsv.On : Rsv.Off;
|
_rsv1 = isData (opcode) && compressed ? Rsv.On : Rsv.Off;
|
||||||
@ -100,24 +100,19 @@ namespace WebSocketSharp
|
|||||||
_opcode = opcode;
|
_opcode = opcode;
|
||||||
_mask = mask;
|
_mask = mask;
|
||||||
|
|
||||||
/* PayloadLength */
|
|
||||||
|
|
||||||
var len = payload.Length;
|
var len = payload.Length;
|
||||||
_payloadLength = len < 126
|
if (len < 126) {
|
||||||
? (byte) len
|
_payloadLength = (byte) len;
|
||||||
: len < 0x010000
|
_extPayloadLength = new byte [0];
|
||||||
? (byte) 126
|
}
|
||||||
: (byte) 127;
|
else if (len < 0x010000) {
|
||||||
|
_payloadLength = (byte) 126;
|
||||||
/* ExtendedPayloadLength */
|
_extPayloadLength = ((ushort) len).ToByteArrayInternally (ByteOrder.Big);
|
||||||
|
}
|
||||||
_extPayloadLength = _payloadLength < 126
|
else {
|
||||||
? new byte [0]
|
_payloadLength = (byte) 127;
|
||||||
: _payloadLength == 126
|
_extPayloadLength = len.ToByteArrayInternally (ByteOrder.Big);
|
||||||
? ((ushort) len).ToByteArrayInternally (ByteOrder.Big)
|
}
|
||||||
: len.ToByteArrayInternally (ByteOrder.Big);
|
|
||||||
|
|
||||||
/* MaskingKey */
|
|
||||||
|
|
||||||
if (mask == Mask.Mask) {
|
if (mask == Mask.Mask) {
|
||||||
_maskingKey = createMaskingKey ();
|
_maskingKey = createMaskingKey ();
|
||||||
@ -127,8 +122,6 @@ namespace WebSocketSharp
|
|||||||
_maskingKey = new byte [0];
|
_maskingKey = new byte [0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PayloadData */
|
|
||||||
|
|
||||||
_payloadData = payload;
|
_payloadData = payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +286,7 @@ namespace WebSocketSharp
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string dump (WsFrame frame)
|
private static string dump (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
var len = frame.Length;
|
var len = frame.Length;
|
||||||
var cnt = (long) (len / 4);
|
var cnt = (long) (len / 4);
|
||||||
@ -322,21 +315,21 @@ namespace WebSocketSharp
|
|||||||
var headerFmt = String.Format (
|
var headerFmt = String.Format (
|
||||||
@"{0} 01234567 89ABCDEF 01234567 89ABCDEF
|
@"{0} 01234567 89ABCDEF 01234567 89ABCDEF
|
||||||
{0}+--------+--------+--------+--------+\n", spFmt);
|
{0}+--------+--------+--------+--------+\n", spFmt);
|
||||||
|
var lineFmt = String.Format ("{0}|{{1,8}} {{2,8}} {{3,8}} {{4,8}}|\n", cntFmt);
|
||||||
var footerFmt = String.Format ("{0}+--------+--------+--------+--------+", spFmt);
|
var footerFmt = String.Format ("{0}+--------+--------+--------+--------+", spFmt);
|
||||||
|
|
||||||
var output = new StringBuilder (64);
|
var output = new StringBuilder (64);
|
||||||
Func<Action<string, string, string, string>> linePrinter = () => {
|
Func<Action<string, string, string, string>> linePrinter = () => {
|
||||||
long lineCnt = 0;
|
long lineCnt = 0;
|
||||||
var lineFmt = String.Format ("{0}|{{1,8}} {{2,8}} {{3,8}} {{4,8}}|\n", cntFmt);
|
|
||||||
return (arg1, arg2, arg3, arg4) =>
|
return (arg1, arg2, arg3, arg4) =>
|
||||||
output.AppendFormat (lineFmt, ++lineCnt, arg1, arg2, arg3, arg4);
|
output.AppendFormat (lineFmt, ++lineCnt, arg1, arg2, arg3, arg4);
|
||||||
};
|
};
|
||||||
|
|
||||||
var printLine = linePrinter ();
|
|
||||||
output.AppendFormat (headerFmt, String.Empty);
|
output.AppendFormat (headerFmt, String.Empty);
|
||||||
|
|
||||||
|
var printLine = linePrinter ();
|
||||||
var frameAsBytes = frame.ToByteArray ();
|
var frameAsBytes = frame.ToByteArray ();
|
||||||
for (int i = 0; i <= cnt; i++) {
|
for (long i = 0; i <= cnt; i++) {
|
||||||
var j = i * 4;
|
var j = i * 4;
|
||||||
if (i < cnt)
|
if (i < cnt)
|
||||||
printLine (
|
printLine (
|
||||||
@ -366,7 +359,7 @@ namespace WebSocketSharp
|
|||||||
return opcode == Opcode.Text || opcode == Opcode.Binary;
|
return opcode == Opcode.Text || opcode == Opcode.Binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static WsFrame parse (byte [] header, Stream stream, bool unmask)
|
private static WebSocketFrame parse (byte [] header, Stream stream, bool unmask)
|
||||||
{
|
{
|
||||||
/* Header */
|
/* Header */
|
||||||
|
|
||||||
@ -401,7 +394,7 @@ namespace WebSocketSharp
|
|||||||
CloseStatusCode.InconsistentData,
|
CloseStatusCode.InconsistentData,
|
||||||
"The length of payload data of a control frame is greater than 125 bytes.");
|
"The length of payload data of a control frame is greater than 125 bytes.");
|
||||||
|
|
||||||
var frame = new WsFrame ();
|
var frame = new WebSocketFrame ();
|
||||||
frame._fin = fin;
|
frame._fin = fin;
|
||||||
frame._rsv1 = rsv1;
|
frame._rsv1 = rsv1;
|
||||||
frame._rsv2 = rsv2;
|
frame._rsv2 = rsv2;
|
||||||
@ -474,7 +467,7 @@ namespace WebSocketSharp
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string print (WsFrame frame)
|
private static string print (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
/* Opcode */
|
/* Opcode */
|
||||||
|
|
||||||
@ -516,8 +509,8 @@ namespace WebSocketSharp
|
|||||||
RSV3: {3}
|
RSV3: {3}
|
||||||
Opcode: {4}
|
Opcode: {4}
|
||||||
MASK: {5}
|
MASK: {5}
|
||||||
Payload Len: {6}
|
Payload Length: {6}
|
||||||
Extended Payload Len: {7}
|
Extended Payload Length: {7}
|
||||||
Masking Key: {8}
|
Masking Key: {8}
|
||||||
Payload Data: {9}";
|
Payload Data: {9}";
|
||||||
|
|
||||||
@ -539,44 +532,45 @@ Extended Payload Len: {7}
|
|||||||
|
|
||||||
#region Internal Methods
|
#region Internal Methods
|
||||||
|
|
||||||
internal static WsFrame CreateCloseFrame (Mask mask, PayloadData payload)
|
internal static WebSocketFrame CreateCloseFrame (Mask mask, PayloadData payload)
|
||||||
{
|
{
|
||||||
return new WsFrame (Opcode.Close, mask, payload);
|
return new WebSocketFrame (Opcode.Close, mask, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static WsFrame CreatePongFrame (Mask mask, PayloadData payload)
|
internal static WebSocketFrame CreatePongFrame (Mask mask, PayloadData payload)
|
||||||
{
|
{
|
||||||
return new WsFrame (Opcode.Pong, mask, payload);
|
return new WebSocketFrame (Opcode.Pong, mask, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
public static WsFrame CreateCloseFrame (Mask mask, byte [] data)
|
public static WebSocketFrame CreateCloseFrame (Mask mask, byte [] data)
|
||||||
{
|
{
|
||||||
return new WsFrame (Opcode.Close, mask, new PayloadData (data));
|
return new WebSocketFrame (Opcode.Close, mask, new PayloadData (data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WsFrame CreateCloseFrame (Mask mask, CloseStatusCode code, string reason)
|
public static WebSocketFrame CreateCloseFrame (Mask mask, CloseStatusCode code, string reason)
|
||||||
{
|
{
|
||||||
return new WsFrame (Opcode.Close, mask, new PayloadData (((ushort) code).Append (reason)));
|
return new WebSocketFrame (
|
||||||
|
Opcode.Close, mask, new PayloadData (((ushort) code).Append (reason)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WsFrame CreateFrame (
|
public static WebSocketFrame CreateFrame (
|
||||||
Fin fin, Opcode opcode, Mask mask, byte [] data, bool compressed)
|
Fin fin, Opcode opcode, Mask mask, byte [] data, bool compressed)
|
||||||
{
|
{
|
||||||
return new WsFrame (fin, opcode, mask, new PayloadData (data), compressed);
|
return new WebSocketFrame (fin, opcode, mask, new PayloadData (data), compressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WsFrame CreatePingFrame (Mask mask)
|
public static WebSocketFrame CreatePingFrame (Mask mask)
|
||||||
{
|
{
|
||||||
return new WsFrame (Opcode.Ping, mask, new PayloadData ());
|
return new WebSocketFrame (Opcode.Ping, mask, new PayloadData ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WsFrame CreatePingFrame (Mask mask, byte [] data)
|
public static WebSocketFrame CreatePingFrame (Mask mask, byte [] data)
|
||||||
{
|
{
|
||||||
return new WsFrame (Opcode.Ping, mask, new PayloadData (data));
|
return new WebSocketFrame (Opcode.Ping, mask, new PayloadData (data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator<byte> GetEnumerator ()
|
public IEnumerator<byte> GetEnumerator ()
|
||||||
@ -585,23 +579,23 @@ Extended Payload Len: {7}
|
|||||||
yield return b;
|
yield return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WsFrame Parse (byte [] src)
|
public static WebSocketFrame Parse (byte [] src)
|
||||||
{
|
{
|
||||||
return Parse (src, true);
|
return Parse (src, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WsFrame Parse (Stream stream)
|
public static WebSocketFrame Parse (Stream stream)
|
||||||
{
|
{
|
||||||
return Parse (stream, true);
|
return Parse (stream, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WsFrame Parse (byte [] src, bool unmask)
|
public static WebSocketFrame Parse (byte [] src, bool unmask)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream (src))
|
using (var stream = new MemoryStream (src))
|
||||||
return Parse (stream, unmask);
|
return Parse (stream, unmask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WsFrame Parse (Stream stream, bool unmask)
|
public static WebSocketFrame Parse (Stream stream, bool unmask)
|
||||||
{
|
{
|
||||||
var header = stream.ReadBytes (2);
|
var header = stream.ReadBytes (2);
|
||||||
if (header.Length != 2)
|
if (header.Length != 2)
|
||||||
@ -611,19 +605,19 @@ Extended Payload Len: {7}
|
|||||||
return parse (header, stream, unmask);
|
return parse (header, stream, unmask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ParseAsync (Stream stream, Action<WsFrame> completed)
|
public static void ParseAsync (Stream stream, Action<WebSocketFrame> completed)
|
||||||
{
|
{
|
||||||
ParseAsync (stream, true, completed, null);
|
ParseAsync (stream, true, completed, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ParseAsync (
|
public static void ParseAsync (
|
||||||
Stream stream, Action<WsFrame> completed, Action<Exception> error)
|
Stream stream, Action<WebSocketFrame> completed, Action<Exception> error)
|
||||||
{
|
{
|
||||||
ParseAsync (stream, true, completed, error);
|
ParseAsync (stream, true, completed, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ParseAsync (
|
public static void ParseAsync (
|
||||||
Stream stream, bool unmask, Action<WsFrame> completed, Action<Exception> error)
|
Stream stream, bool unmask, Action<WebSocketFrame> completed, Action<Exception> error)
|
||||||
{
|
{
|
||||||
stream.ReadBytesAsync (
|
stream.ReadBytesAsync (
|
||||||
2,
|
2,
|
@ -252,14 +252,14 @@ namespace WebSocketSharp
|
|||||||
_innerStream.Dispose ();
|
_innerStream.Dispose ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public WsFrame ReadFrame ()
|
public WebSocketFrame ReadFrame ()
|
||||||
{
|
{
|
||||||
return WsFrame.Parse (_innerStream, true);
|
return WebSocketFrame.Parse (_innerStream, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReadFrameAsync (Action<WsFrame> completed, Action<Exception> error)
|
public void ReadFrameAsync (Action<WebSocketFrame> completed, Action<Exception> error)
|
||||||
{
|
{
|
||||||
WsFrame.ParseAsync (_innerStream, true, completed, error);
|
WebSocketFrame.ParseAsync (_innerStream, true, completed, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HandshakeRequest ReadHandshakeRequest ()
|
public HandshakeRequest ReadHandshakeRequest ()
|
||||||
@ -272,7 +272,7 @@ namespace WebSocketSharp
|
|||||||
return ReadHandshake<HandshakeResponse> (HandshakeResponse.Parse, 90000);
|
return ReadHandshake<HandshakeResponse> (HandshakeResponse.Parse, 90000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool WriteFrame (WsFrame frame)
|
public bool WriteFrame (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
return Write (frame.ToByteArray ());
|
return Write (frame.ToByteArray ());
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,6 @@
|
|||||||
<Compile Include="Opcode.cs" />
|
<Compile Include="Opcode.cs" />
|
||||||
<Compile Include="PayloadData.cs" />
|
<Compile Include="PayloadData.cs" />
|
||||||
<Compile Include="Rsv.cs" />
|
<Compile Include="Rsv.cs" />
|
||||||
<Compile Include="WsFrame.cs" />
|
|
||||||
<Compile Include="Net\WebSockets\HttpListenerWebSocketContext.cs" />
|
<Compile Include="Net\WebSockets\HttpListenerWebSocketContext.cs" />
|
||||||
<Compile Include="Net\WebSockets\TcpListenerWebSocketContext.cs" />
|
<Compile Include="Net\WebSockets\TcpListenerWebSocketContext.cs" />
|
||||||
<Compile Include="Net\WebSockets\WebSocketContext.cs" />
|
<Compile Include="Net\WebSockets\WebSocketContext.cs" />
|
||||||
@ -135,6 +134,7 @@
|
|||||||
<Compile Include="Net\InputChunkState.cs" />
|
<Compile Include="Net\InputChunkState.cs" />
|
||||||
<Compile Include="Net\ChunkedRequestStream.cs" />
|
<Compile Include="Net\ChunkedRequestStream.cs" />
|
||||||
<Compile Include="Net\QueryStringCollection.cs" />
|
<Compile Include="Net\QueryStringCollection.cs" />
|
||||||
|
<Compile Include="WebSocketFrame.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user