C# Class BF2Statistics.Gamespy.Net.GamespyTcpSocket

This class represents a high performance Async Tcp Socket wrapper that is used to act as a base for all Gamespy protocol Tcp connections.
Inheritance: IDisposable
Show file Open project: BF2Statistics/ControlCenter Class Usage Examples

Protected Properties

Property Type Description
BufferManager BF2Statistics.Net.BufferManager
BufferSizePerEventArg int
ConcurrentAcceptPoolSize int
ConnectionEnforceMode EnforceMode
FullErrorMessage string
Listener Socket
MaxConnectionsEnforcer System.Threading.SemaphoreSlim
MaxNumConnections int
SocketAcceptPool BF2Statistics.Net.SocketAsyncEventArgsPool
SocketReadWritePool BF2Statistics.Net.SocketAsyncEventArgsPool
WaitTimeout int

Public Methods

Method Description
Dispose ( ) : void

Releases all Objects held by this socket. Will also shutdown the socket if its still running

GamespyTcpSocket ( int Port, int MaxConnections ) : System

Creates a new TCP socket for handling Gamespy Protocol

Release ( GamespyTcpStream Stream ) : void

Releases the Stream's SocketAsyncEventArgs back to the pool, and free's up another slot for a new client to connect

Protected Methods

Method Description
PrepareAccept ( SocketAsyncEventArgs AcceptEventArg ) : void

Once a connection has been received, its handed off here to convert it into our client object, and prepared to be handed off to the parent for processing

ProcessAccept ( GamespyTcpStream Stream ) : void

When a new connection is established, the parent class is responsible for processing the connected client

ShutdownSocket ( ) : void

When called, this method will stop accepting new clients, and stop all I/O ops on all connections. Dispose still needs to be called afterwards!

StartAcceptAsync ( ) : void

Begins accepting a new Connection asynchronously

Method Details

Dispose() public method

Releases all Objects held by this socket. Will also shutdown the socket if its still running
public Dispose ( ) : void
return void

GamespyTcpSocket() public method

Creates a new TCP socket for handling Gamespy Protocol
public GamespyTcpSocket ( int Port, int MaxConnections ) : System
Port int The port this socket will be bound to
MaxConnections int The maximum number of concurrent connections
return System

PrepareAccept() protected method

Once a connection has been received, its handed off here to convert it into our client object, and prepared to be handed off to the parent for processing
protected PrepareAccept ( SocketAsyncEventArgs AcceptEventArg ) : void
AcceptEventArg System.Net.Sockets.SocketAsyncEventArgs
return void

ProcessAccept() protected abstract method

When a new connection is established, the parent class is responsible for processing the connected client
protected abstract ProcessAccept ( GamespyTcpStream Stream ) : void
Stream GamespyTcpStream A GamespyTcpStream object that wraps the I/O AsyncEventArgs and socket
return void

Release() public method

Releases the Stream's SocketAsyncEventArgs back to the pool, and free's up another slot for a new client to connect
public Release ( GamespyTcpStream Stream ) : void
Stream GamespyTcpStream The GamespyTcpStream object that is being released.
return void

ShutdownSocket() protected method

When called, this method will stop accepting new clients, and stop all I/O ops on all connections. Dispose still needs to be called afterwards!
protected ShutdownSocket ( ) : void
return void

StartAcceptAsync() protected method

Begins accepting a new Connection asynchronously
protected StartAcceptAsync ( ) : void
return void

Property Details

BufferManager protected property

Buffers for sockets are unmanaged by .NET, which means that memory will get fragmented because the GC can't touch these byte arrays. So we will manage our buffers manually
protected BufferManager,BF2Statistics.Net BufferManager
return BF2Statistics.Net.BufferManager

BufferSizePerEventArg protected property

The amount of bytes each SocketAysncEventArgs object will get assigned to in the buffer manager.
protected int BufferSizePerEventArg
return int

ConcurrentAcceptPoolSize protected property

The initial size of the concurrent accept pool when accepting new connections. High volume of connections will increase the pool size if need be 4 should be a pretty good init compacity since accepting a client is pretty fast
protected int ConcurrentAcceptPoolSize
return int

ConnectionEnforceMode protected property

Determines where the MaxConnectionsEnforcer stops to wait for a spot to open, and allow the connecting client through.
protected EnforceMode ConnectionEnforceMode
return EnforceMode

FullErrorMessage protected property

The error message to display if the server is full. Only works if ConnectionEnforceMode is set to DuringPrepare. If left empty, no message will be sent back to the client
protected string FullErrorMessage
return string

Listener protected property

Our Listening Socket
protected Socket Listener
return Socket

MaxConnectionsEnforcer protected property

Use a Semaphore to prevent more then the MaxNumConnections clients from logging in at once.
protected SemaphoreSlim,System.Threading MaxConnectionsEnforcer
return System.Threading.SemaphoreSlim

MaxNumConnections protected property

Max number of concurrent open and active connections. Increasing this number will also increase the IO Buffer by BufferSizePerEventArg * 2
protected int MaxNumConnections
return int

SocketAcceptPool protected property

A pool of reusable SocketAsyncEventArgs objects for accept operations
protected SocketAsyncEventArgsPool,BF2Statistics.Net SocketAcceptPool
return BF2Statistics.Net.SocketAsyncEventArgsPool

SocketReadWritePool protected property

A pool of reusable SocketAsyncEventArgs objects for receive and send socket operations
protected SocketAsyncEventArgsPool,BF2Statistics.Net SocketReadWritePool
return BF2Statistics.Net.SocketAsyncEventArgsPool

WaitTimeout protected property

If the ConnectionEnforceMode is set to DuringPrepare, then the wait timeout is set here
protected int WaitTimeout
return int