示例#1
0
		public static void Release( Packet p ) {
			if( p != null )
				p.Release();
		}
示例#2
0
		public static void Release( ref Packet p ) {
			if( p != null )
				p.Release();

			p = null;
		}
示例#3
0
		public static Packet SetStatic( Packet p ) {
			p.SetStatic();
			return p;
		}
示例#4
0
		public static Packet Acquire( Packet p ) {
			p.Acquire();
			return p;
		}
示例#5
0
		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 );

		}