public static void Release(ref Packet p)
        {
            if (p != null)
                p.Release();

            p = null;
        }
 public static Packet Acquire(Packet p)
 {
     p.Acquire();
     return p;
 }
 public static void Release(Packet p)
 {
     if (p != null)
         p.Release();
 }
 public static Packet SetStatic(Packet p)
 {
     p.SetStatic();
     return p;
 }
        public virtual void Send(Packet p)
        {
            if (m_Socket == null || m_BlockAllPackets)
            {
                p.OnSend();
                return;
            }

            int length;
            byte[] buffer = p.Compile(m_CompressionEnabled, out length);

            if (buffer != null)
            {
                if (buffer.Length <= 0 || length <= 0)
                {
                    p.OnSend();
                    return;
                }

                if (m_Encoder != null)
                {
                    m_Encoder.EncodeOutgoingPacket(this, ref buffer, ref length);
                }

                try
                {
                    SendQueue.Gram gram;

                    lock (m_SendQueue)
                    {
                        gram = m_SendQueue.Enqueue(buffer, length);
                    }

                    if (gram != null)
                    {
#if Framework_4_0
                        m_SendEventArgs.SetBuffer(gram.Buffer, 0, gram.Length);
                        Send_Start();
#else
						try {
							m_Socket.BeginSend( gram.Buffer, 0, gram.Length, SocketFlags.None, m_OnSend, m_Socket );
						} catch ( Exception ex ) {
							TraceException( ex );
							Dispose( false );
						}
#endif
                    }
                }
                catch (CapacityExceededException)
                {
                    Console.WriteLine("Client: {0}: Too much data pending, disconnecting...", this);
                    Dispose(false);
                }

                p.OnSend();
            }
            else
            {
                Console.WriteLine("Client: {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();
            }
        }