Exemplo n.º 1
0
        // a bit dirty. only used by WorldClientCollection
        public void Send(SegmentStream stream)
        {
            if (Socket == null || !Connected)
            {
                stream.Dispose();
                return;
            }

            var args = ObjectPoolMgr.ObtainObject <PoolableSocketArgs>();

            try
            {
                args.Completed += OnSendCompleted;
                args.SetBuffer(stream.Segment.Buffer.Array, stream.Segment.Offset, (int)(stream.Position));
                args.UserToken = stream;

                if (!Socket.SendAsync(args))
                {
                    args.Completed -= OnSendCompleted;
                    stream.Dispose();
                    ObjectPoolMgr.ReleaseObject(args);
                }
            }
            catch
            {
                args.Dispose();
                stream.Dispose();
                // args could be disposed if an error occured
                throw;
            }
        }
Exemplo n.º 2
0
        public static SocketAsyncEventArgs AcquireSocketArg()
        {
            var args = ObjectPoolMgr.ObtainObject <SocketAsyncEventArgs>();

            CleanSocketArg(args);
            return(args);
        }
Exemplo n.º 3
0
        public static SocketAsyncEventArgs AcquireSocketArg()
        {
            //Interlocked.Increment(ref s_OutstandingArgs);
            //Interlocked.Increment(ref s_AcquiredArgs);
            //Console.WriteLine("Acquiring SocketAsyncEventArg {0}:{1}", s_OutstandingArgs, s_AcquiredArgs);
            SocketAsyncEventArgs args = ObjectPoolMgr.ObtainObject <SocketAsyncEventArgs>();

            CleanSocketArg(args);

            return(args);
        }
Exemplo n.º 4
0
 public void Send(SegmentStream stream)
 {
     if (this.Socket != null && this.Connected)
     {
         SocketAsyncEventArgs socketAsyncEventArgs = ObjectPoolMgr.ObtainObject <SocketAsyncEventArgs>();
         socketAsyncEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(this.OnSendCompleted);
         socketAsyncEventArgs.SetBuffer(stream.Segment.Buffer.Array, stream.Segment.Offset, (int)stream.Position);
         socketAsyncEventArgs.UserToken = stream;
         if (!this.Socket.SendAsync(socketAsyncEventArgs))
         {
             socketAsyncEventArgs.Completed -= new EventHandler <SocketAsyncEventArgs>(this.OnSendCompleted);
             stream.Dispose();
             ObjectPoolMgr.ReleaseObject <SocketAsyncEventArgs>(socketAsyncEventArgs);
         }
         this.LastActivity = DateTime.Now;
     }
 }
Exemplo n.º 5
0
        public PoolableSocketArgs PopSocketArg()
        {
            var arg = ObjectPoolMgr.ObtainObject <PoolableSocketArgs>();

            return(arg);
        }
Exemplo n.º 6
0
 public SocketAsyncEventArgs PopSocketArg()
 {
     return(ObjectPoolMgr.ObtainObject <SocketAsyncEventArgs>());
 }