Squishy.Network.Throttle.UpdateUpload C# (CSharp) Method

UpdateUpload() private method

private UpdateUpload ( int newBytes ) : void
newBytes int
return void
        internal void UpdateUpload(int newBytes)
        {
            if (TrafficWatch.Active && Active)
            {
                sentBytes += newBytes;
                uploadSuspended = sentBytes >= (maxUploadSpeed*TrafficWatch.PollSpan.TotalSeconds);
            }
        }

Usage Example

Example #1
0
        private void OnSend(IAsyncResult ar)
        {
            lock (sendLock)
            {
                if (isdisconnecting)
                {
                    return;
                }

                int n;
                try
                {
                    n = sock.EndSend(ar);
                    totalSentBytes += n;
                    if (UploadThrottled)
                    {
                        currentSentBytes += n;
                        throttle.UpdateUpload(n);
                    }
                    else
                    {
                        currentUpSpeed   = CalculateUpBps();
                        currentSentBytes = n;
                        lastSendTime     = DateTime.Now;
                    }

                    var buf = (ByteBuffer)ar.AsyncState;
                    int r   = buf.length - n;
                    if (r > 0)
                    {
                        buf.offset = buf.bytes.Length - r;
                        SendNow(buf);
                    }
                    else if (sendQueue.Count > 0)
                    {
                        SendNow(sendQueue.Dequeue());
                    }
                    else
                    {
                        writing = false;
                        if (closing)
                        {
                            DisconnectNow(false);
                        }
                    }
                }
                catch (ObjectDisposedException)
                {
                    // socket has been closed
                    return;
                }
                catch
                {
                    DisconnectNow(true);
                    return;
                }

                SentNotify(n, writing);
            }
        }