Exemplo n.º 1
0
        public static void Release(ref Packet p)
        {
            if (p != null)
                p.Release();

            p = null;
        }
Exemplo n.º 2
0
 public static void Release(Packet p)
 {
     if (p != null)
         p.Release();
 }
Exemplo n.º 3
0
 public static Packet SetStatic(Packet p)
 {
     p.SetStatic();
     return p;
 }
Exemplo n.º 4
0
 public static Packet Acquire(Packet p)
 {
     p.Acquire();
     return p;
 }
        public virtual void Send(Packet p)
        {
            if (_socket == null)
            {
                p.OnSend();
                return;
            }

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

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

                try
                {
                    SocketAsyncEventArgs args = new SocketAsyncEventArgs();

                    args.SetBuffer(buffer, 0, length);
                    args.RemoteEndPoint = _hostEndPoint;
                    args.UserToken = this;

                    _socket.SendAsync(args);
                }
                catch (CapacityExceededException)
                {
                    Tracer.Error("Too much data pending, disconnecting...");
                    Dispose();
                }
                catch (Exception ex)
                {
                    Tracer.Error(ex);
                    Dispose();
                }

                p.OnSend();
            }
            else
            {
                Tracer.Error("Null buffer send, disconnecting...");
                Tracer.Error(new StackTrace());

                Dispose();
            }
        }