Platform.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Sockets;
  6. namespace SuperSocket.Common
  7. {
  8. /// <summary>
  9. /// This class is designed for detect platform attribute in runtime
  10. /// </summary>
  11. public static class Platform
  12. {
  13. static Platform()
  14. {
  15. try
  16. {
  17. var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  18. socket.IOControl(IOControlCode.KeepAliveValues, null, null);
  19. SupportSocketIOControlByCodeEnum = true;
  20. }
  21. catch (NotSupportedException)
  22. {
  23. SupportSocketIOControlByCodeEnum = false;
  24. }
  25. catch (NotImplementedException)
  26. {
  27. SupportSocketIOControlByCodeEnum = false;
  28. }
  29. catch (Exception)
  30. {
  31. SupportSocketIOControlByCodeEnum = true;
  32. }
  33. Type t = Type.GetType("Mono.Runtime");
  34. IsMono = t != null;
  35. }
  36. /// <summary>
  37. /// Gets a value indicating whether [support socket IO control by code enum].
  38. /// </summary>
  39. /// <value>
  40. /// <c>true</c> if [support socket IO control by code enum]; otherwise, <c>false</c>.
  41. /// </value>
  42. public static bool SupportSocketIOControlByCodeEnum { get; private set; }
  43. /// <summary>
  44. /// Gets a value indicating whether this instance is mono.
  45. /// </summary>
  46. /// <value>
  47. /// <c>true</c> if this instance is mono; otherwise, <c>false</c>.
  48. /// </value>
  49. public static bool IsMono { get; private set; }
  50. }
  51. }