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); } }
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); } }
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); } }
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); } }
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); } }
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); } }