You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.6 KiB

3 years ago
2 weeks ago
3 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. namespace Apewer.Web
  6. {
  7. internal sealed class MiniStreamAsyncResult : IAsyncResult
  8. {
  9. object locker = new object();
  10. ManualResetEvent handle;
  11. bool completed;
  12. internal byte[] Buffer = null;
  13. internal int Offset = 0;
  14. internal int Count = 0;
  15. internal AsyncCallback Callback = null;
  16. internal object State = null;
  17. internal int SynchRead = 0;
  18. internal Exception Error = null;
  19. public void Complete(Exception e)
  20. {
  21. Error = e;
  22. Complete();
  23. }
  24. public void Complete()
  25. {
  26. lock (locker)
  27. {
  28. if (completed) return;
  29. completed = true;
  30. if (handle != null) handle.Set();
  31. if (Callback != null) Callback.BeginInvoke(this, null, null);
  32. }
  33. }
  34. public object AsyncState
  35. {
  36. get { return State; }
  37. }
  38. public WaitHandle AsyncWaitHandle
  39. {
  40. get
  41. {
  42. lock (locker)
  43. {
  44. if (handle == null) handle = new ManualResetEvent(completed);
  45. }
  46. return handle;
  47. }
  48. }
  49. public bool CompletedSynchronously
  50. {
  51. get { return (SynchRead == Count); }
  52. }
  53. public bool IsCompleted
  54. {
  55. get
  56. {
  57. lock (locker)
  58. {
  59. return completed;
  60. }
  61. }
  62. }
  63. }
  64. }