DtlsTransport.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Tls
  6. {
  7. public class DtlsTransport
  8. : DatagramTransport
  9. {
  10. private readonly DtlsRecordLayer mRecordLayer;
  11. internal DtlsTransport(DtlsRecordLayer recordLayer)
  12. {
  13. this.mRecordLayer = recordLayer;
  14. }
  15. public virtual int GetReceiveLimit()
  16. {
  17. return mRecordLayer.GetReceiveLimit();
  18. }
  19. public virtual int GetSendLimit()
  20. {
  21. return mRecordLayer.GetSendLimit();
  22. }
  23. public virtual int Receive(byte[] buf, int off, int len, int waitMillis)
  24. {
  25. try
  26. {
  27. return mRecordLayer.Receive(buf, off, len, waitMillis);
  28. }
  29. catch (TlsFatalAlert fatalAlert)
  30. {
  31. mRecordLayer.Fail(fatalAlert.AlertDescription);
  32. throw fatalAlert;
  33. }
  34. catch (IOException e)
  35. {
  36. mRecordLayer.Fail(AlertDescription.internal_error);
  37. throw e;
  38. }
  39. catch (Exception e)
  40. {
  41. mRecordLayer.Fail(AlertDescription.internal_error);
  42. throw new TlsFatalAlert(AlertDescription.internal_error, e);
  43. }
  44. }
  45. public virtual void Send(byte[] buf, int off, int len)
  46. {
  47. try
  48. {
  49. mRecordLayer.Send(buf, off, len);
  50. }
  51. catch (TlsFatalAlert fatalAlert)
  52. {
  53. mRecordLayer.Fail(fatalAlert.AlertDescription);
  54. throw fatalAlert;
  55. }
  56. catch (IOException e)
  57. {
  58. mRecordLayer.Fail(AlertDescription.internal_error);
  59. throw e;
  60. }
  61. catch (Exception e)
  62. {
  63. mRecordLayer.Fail(AlertDescription.internal_error);
  64. throw new TlsFatalAlert(AlertDescription.internal_error, e);
  65. }
  66. }
  67. public virtual void Close()
  68. {
  69. mRecordLayer.Close();
  70. }
  71. }
  72. }
  73. #pragma warning restore
  74. #endif