コード例 #1
0
        public virtual void SendCompleted(SendArgs outgoing)
        {
            outgoing.NotifySent();

            lock (_sendQueue)
            {
                sending = SendMore(outgoing);

                if (!sending)
                {
                    outgoing.conn = null;
                    Server.SendSocketPool.PushBack(outgoing);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Attempts to send as many queued packets in one operation
        /// </summary>
        /// <param name="preallocated">A previously allocated arg</param>
        /// <returns>True when the argument is queued to send</returns>
        private bool SendMore(SendArgs preallocated = null)
        {
            bool queued = false;

            if (preallocated == null)
            {
                preallocated = Server.SendSocketPool.PopFront();
                preallocated.SetBuffer(null, 0, 0);
            }

            preallocated.conn = this;

            var total = 0;

            while (_sendQueue.TryDequeue(out SendRequest request) && total++ < MaxPacketsPerOperation)
            {
                preallocated.Enqueue(request);
            }

            if (preallocated.Prepare())
            {
                try
                {
                    queued = Source.SendAsync(preallocated);
                }
                catch (SocketException e)
                {
                    HandleError(e.SocketErrorCode);
                }
                catch (ObjectDisposedException)
                {
                    HandleError(SocketError.OperationAborted);
                }
            }

            return(queued);
        }