Ejemplo n.º 1
0
        public static void QueueAccept(this Socket socket, SocketAcceptTask task)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket", "socket cannot be null");
            }

            task.Socket    = socket;
            task.Exception = null;
            IO.QueueAccept(task);
        }
Ejemplo n.º 2
0
        public void Listen(int backlog)
        {
            if (socket == null)
            {
                socket   = SocketManager.CreateTcp(AddressFamily.InterNetwork);
                outQueue = new ConcurrentQueue <IPacket>();
                monitor.Start();
            }

            socket.Listen(backlog);

            SocketAcceptTask task = new SocketAcceptTask();

            task.Completed += AcceptComplete;

            socket.QueueAccept(task);
        }
Ejemplo n.º 3
0
        private void ExecuteAccept()
        {
            IOBuffer         args = null;
            SocketAcceptTask task = null;

            lock (acceptPool)
                lock (acceptQueue) {
                    if (acceptPool.Count == 0 || acceptQueue.Count == 0)
                    {
                        return;
                    }

                    args = acceptPool.Pop();
                    task = acceptQueue.Dequeue();

                    task.Execute(args);
                }
        }
Ejemplo n.º 4
0
        private void AcceptComplete(object sender, IOTaskCompleteEventArgs <SocketAcceptTask> e)
        {
            SocketAcceptTask task = (SocketAcceptTask)e.Task;

            if (task.Exception == null)
            {
                var x = Accepted;
                if (x != null)
                {
                    x(this, new AcceptEventArgs(new AresTcpSocket(Formatter, task.AcceptSocket)));
                }
            }

            if (socket != null)
            {
                socket.QueueAccept(task);
            }
        }
Ejemplo n.º 5
0
 public void QueueAccept(SocketAcceptTask task)
 {
     lock (acceptQueue) acceptQueue.Enqueue(task);
 }