Permalink
Browse files

Implemented maxframesize

  • Loading branch information...
DorianGray committed Dec 19, 2011
1 parent 55e03bf commit 16cc4978fc4a60410c16ad67e03c975745876f7c
@@ -21,6 +21,11 @@ public class Context : IDisposable
/// </summary>
public byte[] Buffer;
/// <summary>
/// The max frame that we will accept from the client
/// </summary>
public UInt64 MaxFrameSize;
/// <summary>
/// Whether or not the TCPClient is still connected.
/// </summary>
@@ -55,6 +55,15 @@ public Header Header
/// </summary>
public string RequestPath = "/";
/// <summary>
/// The maximum frame size
/// </summary>
public UInt64 MaxFrameSize
{
get { return _context.MaxFrameSize; }
set { _context.MaxFrameSize = value; }
}
/// <summary>
/// Initializes a new instance of the <see cref="UserContext"/> class.
/// </summary>
@@ -15,28 +15,35 @@ public override void HandleRequest(Context context)
if (context.IsSetup)
{
context.UserContext.DataFrame.Append(context.Buffer, true);
switch (context.UserContext.DataFrame.State)
if (context.UserContext.DataFrame.Length <= context.MaxFrameSize)
{
case DataFrame.DataState.Complete:
context.UserContext.OnReceive();
break;
case DataFrame.DataState.Closed:
context.UserContext.Send(context.UserContext.DataFrame.CreateInstance(), false, true);
break;
case DataFrame.DataState.Ping:
context.UserContext.DataFrame.State = DataFrame.DataState.Complete;
DataFrame dataFrame = context.UserContext.DataFrame.CreateInstance();
dataFrame.State = DataFrame.DataState.Pong;
List<ArraySegment<byte>> pingData = context.UserContext.DataFrame.AsRaw();
foreach (var item in pingData)
{
dataFrame.Append(item.Array);
}
context.UserContext.Send(dataFrame);
break;
case DataFrame.DataState.Pong:
context.UserContext.DataFrame.State = DataFrame.DataState.Complete;
break;
switch (context.UserContext.DataFrame.State)
{
case DataFrame.DataState.Complete:
context.UserContext.OnReceive();
break;
case DataFrame.DataState.Closed:
context.UserContext.Send(context.UserContext.DataFrame.CreateInstance(), false, true);
break;
case DataFrame.DataState.Ping:
context.UserContext.DataFrame.State = DataFrame.DataState.Complete;
DataFrame dataFrame = context.UserContext.DataFrame.CreateInstance();
dataFrame.State = DataFrame.DataState.Pong;
List<ArraySegment<byte>> pingData = context.UserContext.DataFrame.AsRaw();
foreach (var item in pingData)
{
dataFrame.Append(item.Array);
}
context.UserContext.Send(dataFrame);
break;
case DataFrame.DataState.Pong:
context.UserContext.DataFrame.State = DataFrame.DataState.Complete;
break;
}
}
else
{
context.Dispose();//Disconnect if over MaxFrameSize
}
}
else

3 comments on commit 16cc497

@ShyRed

This comment has been minimized.

Show comment
Hide comment
@ShyRed

ShyRed Dec 19, 2011

Nice addition, but please initialize MaxFrameSize with a small default value and/or make sure to emphasize that one should make sure to set this value.

Right now it is initialized with 0 which means that the socket will close as soon as a message is received.

ShyRed replied Dec 19, 2011

Nice addition, but please initialize MaxFrameSize with a small default value and/or make sure to emphasize that one should make sure to set this value.

Right now it is initialized with 0 which means that the socket will close as soon as a message is received.

@DorianGray

This comment has been minimized.

Show comment
Hide comment
@DorianGray

DorianGray Dec 20, 2011

Member

I'm pretty sure I fixed that. Are you sure you're looking at latest? It initialized to uint64.maxvalue

Member

DorianGray replied Dec 20, 2011

I'm pretty sure I fixed that. Are you sure you're looking at latest? It initialized to uint64.maxvalue

@ShyRed

This comment has been minimized.

Show comment
Hide comment
@ShyRed

ShyRed Dec 20, 2011

Yep, you fixed it in a commit after this one. ;-)

ShyRed replied Dec 20, 2011

Yep, you fixed it in a commit after this one. ;-)

Please sign in to comment.