All pastes #95347 Raw Edit

Stuff

public text v1 · immutable
#95347 ·published 2006-07-21 22:50 UTC
rendered paste body
while( totalSent < file.Length )
            {
                int chunkSize = ( int )Math.Min( ( long )_CopyBuffer.Length, sStream.Length - sStream.Position );

                sStream.Read( _CopyBuffer, 0, chunkSize );
                dStream.Write( _CopyBuffer, 0, chunkSize );

                if( GetFlag( CopyFlags.Scan ) )
                    badCount += InternalScan( _CopyBuffer );

                totalSent += chunkSize;
                _CopySize += chunkSize;
                sent += chunkSize;

                bool reset = false;

                if( _ClipBandwidth && start + TimeSpan.FromSeconds( 1.0 ) < DateTime.Now )
                {
                    reset = true;
                }
                else if( _ClipBandwidth && _MaxBandwidth == 0 )
                {
                    while( _MaxBandwidth == 0 )
                    {
                        Thread.Sleep( 500 );
                    }
                    reset = true;
                }
                else if( _ClipBandwidth && sent > _MaxBandwidth )
                {
                    int toSleep = 1000 - ( DateTime.Now.Millisecond - start.Millisecond );
                    Thread.Sleep( toSleep );
                    reset = true;
                }

                if( reset )
                {
                    sent = 0;
                    start = DateTime.Now;
                }
         }