PatientFileStream.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.IO;
  2. namespace WinSCP
  3. {
  4. internal class PatientFileStream : FileStream
  5. {
  6. public PatientFileStream(Session session, string path, FileMode mode, FileAccess access, FileShare share) :
  7. base(path, mode, access, share)
  8. {
  9. _session = session;
  10. }
  11. public override int Read(byte[] array, int offset, int count)
  12. {
  13. int result;
  14. int interval = 50;
  15. do
  16. {
  17. result = base.Read(array, offset, count);
  18. if (result == 0)
  19. {
  20. _session.Logger.WriteLine("Waiting for log update and dispatching events for {0}", interval);
  21. _session.DispatchEvents(interval);
  22. _session.CheckForTimeout();
  23. if (interval < 500)
  24. {
  25. interval *= 2;
  26. }
  27. }
  28. }
  29. // We always want to return something.
  30. // No attempt to detect end real of file is needed,
  31. // as we should not try to read beyond the final closing tag
  32. while (result == 0);
  33. return result;
  34. }
  35. private Session _session;
  36. }
  37. }