WebSocket.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. using System;
  29. using System.IO;
  30. using System.Threading;
  31. using System.Threading.Tasks;
  32. using System.Runtime.CompilerServices;
  33. namespace System.Net.WebSockets
  34. {
  35. public abstract class WebSocket : IDisposable
  36. {
  37. protected WebSocket ()
  38. {
  39. }
  40. public abstract Nullable<WebSocketCloseStatus> CloseStatus { get; }
  41. public abstract string CloseStatusDescription { get; }
  42. public abstract WebSocketState State { get; }
  43. public abstract string SubProtocol { get; }
  44. [MonoTODO]
  45. public static TimeSpan DefaultKeepAliveInterval {
  46. get {
  47. throw new NotImplementedException ();
  48. }
  49. }
  50. public abstract void Abort ();
  51. public abstract Task CloseAsync (WebSocketCloseStatus closeStatus,
  52. string statusDescription,
  53. CancellationToken cancellationToken);
  54. public abstract Task CloseOutputAsync (WebSocketCloseStatus closeStatus,
  55. string statusDescription,
  56. CancellationToken cancellationToken);
  57. public abstract Task<WebSocketReceiveResult> ReceiveAsync (ArraySegment<byte> buffer,
  58. CancellationToken cancellationToken);
  59. public abstract Task SendAsync (ArraySegment<byte> buffer,
  60. WebSocketMessageType messageType,
  61. bool endOfMessage,
  62. CancellationToken cancellationToken);
  63. [MonoTODO]
  64. public static ArraySegment<byte> CreateClientBuffer (int receiveBufferSize, int sendBufferSize)
  65. {
  66. throw new NotImplementedException ();
  67. }
  68. [MonoTODO]
  69. public static WebSocket CreateClientWebSocket (Stream innerStream,
  70. string subProtocol,
  71. int receiveBufferSize,
  72. int sendBufferSize,
  73. TimeSpan keepAliveInterval,
  74. bool useZeroMaskingKey,
  75. ArraySegment<byte> internalBuffer)
  76. {
  77. throw new NotImplementedException ();
  78. }
  79. [MonoTODO]
  80. public static ArraySegment<byte> CreateServerBuffer (int receiveBufferSize)
  81. {
  82. throw new NotImplementedException ();
  83. }
  84. [ObsoleteAttribute, MonoTODO]
  85. public static bool IsApplicationTargeting45 ()
  86. {
  87. return true;
  88. }
  89. [MonoTODO]
  90. public static void RegisterPrefixes ()
  91. {
  92. throw new NotImplementedException ();
  93. }
  94. public abstract void Dispose ();
  95. protected static bool IsStateTerminal (WebSocketState state)
  96. {
  97. return state == WebSocketState.Closed || state == WebSocketState.Aborted;
  98. }
  99. [MonoTODO]
  100. protected static void ThrowOnInvalidState (WebSocketState state, params WebSocketState[] validStates)
  101. {
  102. foreach (var validState in validStates)
  103. if (validState == state)
  104. return;
  105. throw new NotImplementedException ();
  106. }
  107. }
  108. }