Platform.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
  20. SupportSocketIOControlByCodeEnum = true;
  21. }
  22. catch (NotSupportedException)
  23. {
  24. SupportSocketIOControlByCodeEnum = false;
  25. }
  26. catch (NotImplementedException)
  27. {
  28. SupportSocketIOControlByCodeEnum = false;
  29. }
  30. catch (Exception)
  31. {
  32. SupportSocketIOControlByCodeEnum = true;
  33. }
  34. Type t = Type.GetType("Mono.Runtime");
  35. IsMono = t != null;
  36. }
  37. /// <summary>
  38. /// Gets a value indicating whether [support socket IO control by code enum].
  39. /// </summary>
  40. /// <value>
  41. /// <c>true</c> if [support socket IO control by code enum]; otherwise, <c>false</c>.
  42. /// </value>
  43. public static bool SupportSocketIOControlByCodeEnum { get; private set; }
  44. /// <summary>
  45. /// Gets a value indicating whether this instance is mono.
  46. /// </summary>
  47. /// <value>
  48. /// <c>true</c> if this instance is mono; otherwise, <c>false</c>.
  49. /// </value>
  50. public static bool IsMono { get; private set; }
  51. }
  52. }