5 // Jérémie Laval <jeremie dot laval at xamarin dot com>
7 // Copyright 2013 Xamarin Inc (http://www.xamarin.com).
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:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
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
32 using System.Threading;
33 using System.Threading.Tasks;
34 using System.Runtime.CompilerServices;
36 namespace System.Net.WebSockets
38 public abstract class WebSocket : IDisposable
40 protected WebSocket ()
45 public abstract Nullable<WebSocketCloseStatus> CloseStatus { get; }
46 public abstract string CloseStatusDescription { get; }
47 public abstract WebSocketState State { get; }
48 public abstract string SubProtocol { get; }
51 public static TimeSpan DefaultKeepAliveInterval {
53 throw new NotImplementedException ();
57 public abstract void Abort ();
59 public abstract Task CloseAsync (WebSocketCloseStatus closeStatus,
60 string statusDescription,
61 CancellationToken cancellationToken);
63 public abstract Task CloseOutputAsync (WebSocketCloseStatus closeStatus,
64 string statusDescription,
65 CancellationToken cancellationToken);
67 public abstract Task<WebSocketReceiveResult> ReceiveAsync (ArraySegment<byte> buffer,
68 CancellationToken cancellationToken);
70 public abstract Task SendAsync (ArraySegment<byte> buffer,
71 WebSocketMessageType messageType,
73 CancellationToken cancellationToken);
76 public static ArraySegment<byte> CreateClientBuffer (int receiveBufferSize, int sendBufferSize)
78 throw new NotImplementedException ();
82 public static WebSocket CreateClientWebSocket (Stream innerStream,
84 int receiveBufferSize,
86 TimeSpan keepAliveInterval,
87 bool useZeroMaskingKey,
88 ArraySegment<byte> internalBuffer)
90 throw new NotImplementedException ();
94 public static ArraySegment<byte> CreateServerBuffer (int receiveBufferSize)
96 throw new NotImplementedException ();
99 [ObsoleteAttribute, MonoTODO]
100 public static bool IsApplicationTargeting45 ()
106 public static void RegisterPrefixes ()
108 throw new NotImplementedException ();
111 public abstract void Dispose ();
113 protected static bool IsStateTerminal (WebSocketState state)
115 return state == WebSocketState.Closed || state == WebSocketState.Aborted;
119 protected static void ThrowOnInvalidState (WebSocketState state, params WebSocketState[] validStates)
121 foreach (var validState in validStates)
122 if (validState == state)
125 throw new NotImplementedException ();