public static void Release( Packet p ) { if( p != null ) p.Release(); }
public static void Release( ref Packet p ) { if( p != null ) p.Release(); p = null; }
public static Packet SetStatic( Packet p ) { p.SetStatic(); return p; }
public static Packet Acquire( Packet p ) { p.Acquire(); return p; }
public virtual void Send( Packet p ) { if( mSocket == null || mBlockAllPackets ) { p.OnSend(); return; } PacketSendProfile prof = PacketSendProfile.Acquire( p.GetType() ); int length = 0; byte[] buffer = p.Compile( out length ); if( buffer == null ) { CConsole.ErrorLine( "{0}: null buffer send, disconnecting...", this ); using( StreamWriter op = new StreamWriter( "null_send.log", true ) ) { op.WriteLine( "{0} Client", "{1}: null buffer send, disconnecting...", DateTime.Now, this ); op.WriteLine( new System.Diagnostics.StackTrace() ); } Dispose(); return; } if( buffer.Length <= 0 || length <= 0 ) { p.OnSend(); return; } if( prof != null ) prof.Start(); if( mEncoder != null ) mEncoder.EncodeOutgoingPacket( this, ref buffer, ref length ); try { Int16 pID = BitConverter.ToInt16( buffer, 0 ); CConsole.DebugLine( "{0}: sending Packet 0x{1:X4}", this, pID ); mSocket.BeginSend( buffer, 0, length, SocketFlags.None, mOnSend, mSocket ); } catch( Exception ex ) { ExceptionHandler.Trace( ex ); Dispose( false ); } p.OnSend(); if( prof != null ) prof.Finish( length ); }