Пример #1
0
        private static void FinishSend(AsyncIOState data)
        {
            try
            {
                var transferred = (int)data.Transferred;
                if (transferred == 0)
                {
                    data.Callback(false, 0, data.State);
                    TransferCache.Enqueue(data);
                }
                else
                {
                    data.PeerMonitor?.BytesSent(transferred, data.TransferType);
                    data.ManagerMonitor?.BytesSent(transferred, data.TransferType);

                    data.Offset    += transferred;
                    data.Remaining -= transferred;
                    if (data.Remaining == 0)
                    {
                        data.Callback(true, data.Count, data.State);
                        TransferCache.Enqueue(data);
                    }
                    else
                    {
                        lock (SendQueue)
                            SendOrEnqueue(data);
                    }
                }
            }
            catch
            {
                data.Callback(false, 0, data.State);
                TransferCache.Enqueue(data);
            }
        }
Пример #2
0
        static void SendOrEnqueue(AsyncIOState data)
        {
            int count = Math.Min(ChunkLength, data.Remaining);

            if (data.RateLimiter == null || data.RateLimiter.TryProcess(1))
            {
                try {
                    data.Connection.BeginSend(data.Buffer, data.Offset, count, EndSendCallback, data);
                } catch {
                    data.Callback(false, 0, data.State);
                    transferCache.Enqueue(data);
                }
            }
            else
            {
                sendQueue.Enqueue(data);
            }
        }
Пример #3
0
        private static async void SendOrEnqueue(AsyncIOState data)
        {
            var count = Math.Min(ChunkLength, data.Remaining);

            if (data.RateLimiter == null || data.RateLimiter.TryProcess(1))
            {
                try
                {
                    data.Transferred = await data.Connection.SendAsync(data.Buffer, data.Offset, count);

                    FinishSend(data);
                }
                catch
                {
                    data.Callback(false, 0, data.State);
                    TransferCache.Enqueue(data);
                }
            }
            else
            {
                SendQueue.Enqueue(data);
            }
        }
Пример #4
0
 static void SendOrEnqueue(AsyncIOState data)
 {
     int count = Math.Min (ChunkLength, data.Remaining);
     if (data.RateLimiter == null || data.RateLimiter.TryProcess (1)) {
         try {
             data.Connection.BeginSend (data.Buffer, data.Offset, count, EndSendCallback, data);
         } catch {
             data.Callback (false, 0, data.State);
             transferCache.Enqueue (data);
         }
     } else {
         sendQueue.Enqueue (data);
     }
 }
Пример #5
0
 private static void ReceiveOrEnqueue(AsyncIOState data)
 {
     var count = Math.Min(ChunkLength, data.Remaining);
     if (data.RateLimiter == null || data.RateLimiter.TryProcess(1))
     {
         try
         {
             data.Connection.BeginReceive(data.Buffer, data.Offset, count, EndReceiveCallback, data);
         }
         catch
         {
             data.Callback(false, 0, data.State);
             transferCache.Enqueue(data);
         }
     }
     else
     {
         receiveQueue.Enqueue(data);
     }
 }
Пример #6
0
 private static async void SendOrEnqueue(AsyncIOState data)
 {
     var count = Math.Min(ChunkLength, data.Remaining);
     if (data.RateLimiter == null || data.RateLimiter.TryProcess(1))
     {
         try
         {
             data.Transferred = await data.Connection.SendAsync(data.Buffer, data.Offset, count);
             FinishSend(data);
         }
         catch
         {
             data.Callback(false, 0, data.State);
             TransferCache.Enqueue(data);
         }
     }
     else
     {
         SendQueue.Enqueue(data);
     }
 }
Пример #7
0
        private static void FinishSend(AsyncIOState data)
        {
            try
            {
                var transferred = (int) data.Transferred;
                if (transferred == 0)
                {
                    data.Callback(false, 0, data.State);
                    TransferCache.Enqueue(data);
                }
                else
                {
                    data.PeerMonitor?.BytesSent(transferred, data.TransferType);
                    data.ManagerMonitor?.BytesSent(transferred, data.TransferType);

                    data.Offset += transferred;
                    data.Remaining -= transferred;
                    if (data.Remaining == 0)
                    {
                        data.Callback(true, data.Count, data.State);
                        TransferCache.Enqueue(data);
                    }
                    else
                    {
                        lock (SendQueue)
                            SendOrEnqueue(data);
                    }
                }
            }
            catch
            {
                data.Callback(false, 0, data.State);
                TransferCache.Enqueue(data);
            }
        }