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

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

            int length;
            byte[] buffer = p.Compile(_isCompressionEnabled, 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();
            }
        }