WebSocket.cs 4.2 KB

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