WebSocket.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // WebSocket.cs
  3. //
  4. // Authors:
  5. // Jérémie Laval <jeremie dot laval at xamarin dot com>
  6. //
  7. // Copyright 2013 Xamarin Inc (http://www.xamarin.com).
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. //
  27. //
  28. #if NET_4_5
  29. using System;
  30. using System.Runtime.CompilerServices;
  31. namespace System.Net.WebSockets
  32. {
  33. public abstract class WebSocket : IDisposable
  34. {
  35. protected WebSocket ()
  36. {
  37. }
  38. public abstract Nullable<WebSocketCloseStatus> CloseStatus { get; }
  39. public abstract string CloseStatusDescription { get; }
  40. public abstract WebSocketState State { get; }
  41. public abstract string SubProtocol { get; }
  42. [MonoTODO]
  43. public static TimeSpan DefaultKeepAliveInterval {
  44. get {
  45. throw new NotImplementedException ();
  46. }
  47. }
  48. public abstract void Abort ();
  49. public abstract Task CloseAsync (WebSocketCloseStatus closeStatus,
  50. string statusDescription,
  51. CancellationToken cancellationToken);
  52. public abstract Task CloseOutputAsync (WebSocketCloseStatus closeStatus,
  53. string statusDescription,
  54. CancellationToken cancellationToken);
  55. public abstract Task<WebSocketReceiveResult> ReceiveAsync (ArraySegment<byte> buffer,
  56. CancellationToken cancellationToken);
  57. public abstract Task SendAsync (ArraySegment<byte> buffer,
  58. WebSocketMessageType messageType,
  59. bool endOfMessage,
  60. CancellationToken cancellationToken);
  61. [MonoTODO]
  62. public static ArraySegment<byte> CreateClientBuffer (int receiveBufferSize, int sendBufferSize)
  63. {
  64. throw new NotImplementedException ();
  65. }
  66. [MonoTODO]
  67. public static WebSocket CreateClientWebSocket (Stream innerStream,
  68. string subProtocol,
  69. int receiveBufferSize,
  70. int sendBufferSize,
  71. TimeSpan keepAliveInterval,
  72. bool useZeroMaskingKey,
  73. ArraySegment<byte> internalBuffer)
  74. {
  75. throw new NotImplementedException ();
  76. }
  77. [MonoTODO]
  78. public static ArraySegment<byte> CreateServerBuffer (int receiveBufferSize)
  79. {
  80. throw new NotImplementedException ();
  81. }
  82. [ObsoleteAttribute, MonoTODO]
  83. public static bool IsApplicationTargeting45 ()
  84. {
  85. return true;
  86. }
  87. [MonoTODO]
  88. public static void RegisterPrefixes ()
  89. {
  90. throw new NotImplementedException ();
  91. }
  92. public abstract void Dispose ();
  93. protected static bool IsStateTerminal (WebSocketState state)
  94. {
  95. return state == WebSocketState.Closed || state == WebSocketState.Aborted;
  96. }
  97. [MonoTODO]
  98. protected static void ThrowOnInvalidState (WebSocketState state, params WebSocketState[] validStates)
  99. {
  100. foreach (var validState in validStates)
  101. if (validState == state)
  102. return;
  103. throw new NotImplementedException ();
  104. }
  105. }
  106. }
  107. #endif