[sgen] Split up concurrent sweep from worker logic
[mono.git] / mcs / class / System / System.Net.WebSockets / WebSocket.cs
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
29
30 using System;
31 using System.IO;
32 using System.Threading;
33 using System.Threading.Tasks;
34 using System.Runtime.CompilerServices;
35
36 namespace System.Net.WebSockets
37 {
38         public abstract class WebSocket : IDisposable
39         {
40                 protected WebSocket ()
41                 {
42                         
43                 }
44
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; }
49
50                 [MonoTODO]
51                 public static TimeSpan DefaultKeepAliveInterval {
52                         get {
53                                 throw new NotImplementedException ();
54                         }
55                 }
56
57                 public abstract void Abort ();
58                 
59                 public abstract Task CloseAsync (WebSocketCloseStatus closeStatus,
60                                                  string statusDescription,
61                                                  CancellationToken cancellationToken);
62
63                 public abstract Task CloseOutputAsync (WebSocketCloseStatus closeStatus,
64                                                        string statusDescription,
65                                                        CancellationToken cancellationToken);
66
67                 public abstract Task<WebSocketReceiveResult> ReceiveAsync (ArraySegment<byte> buffer,
68                                                                            CancellationToken cancellationToken);
69
70                 public abstract Task SendAsync (ArraySegment<byte> buffer,
71                                                 WebSocketMessageType messageType,
72                                                 bool endOfMessage,
73                                                 CancellationToken cancellationToken);
74
75                 [MonoTODO]
76                 public static ArraySegment<byte> CreateClientBuffer (int receiveBufferSize, int sendBufferSize)
77                 {
78                         throw new NotImplementedException ();
79                 }
80
81                 [MonoTODO]
82                 public static WebSocket CreateClientWebSocket (Stream innerStream,
83                                                                string subProtocol,
84                                                                int receiveBufferSize,
85                                                                int sendBufferSize,
86                                                                TimeSpan keepAliveInterval,
87                                                                bool useZeroMaskingKey,
88                                                                ArraySegment<byte> internalBuffer)
89                 {
90                         throw new NotImplementedException ();
91                 }
92
93                 [MonoTODO]
94                 public static ArraySegment<byte> CreateServerBuffer (int receiveBufferSize)
95                 {
96                         throw new NotImplementedException ();
97                 }
98
99                 [ObsoleteAttribute, MonoTODO]
100                 public static bool IsApplicationTargeting45 ()
101                 {
102                         return true;
103                 }
104
105                 [MonoTODO]
106                 public static void RegisterPrefixes ()
107                 {
108                         throw new NotImplementedException ();
109                 }
110
111                 public abstract void Dispose ();
112
113                 protected static bool IsStateTerminal (WebSocketState state)
114                 {
115                         return state == WebSocketState.Closed || state == WebSocketState.Aborted;
116                 }
117
118                 [MonoTODO]
119                 protected static void ThrowOnInvalidState (WebSocketState state, params WebSocketState[] validStates)
120                 {
121                         foreach (var validState in validStates)
122                                 if (validState == state)
123                                         return;
124
125                         throw new NotImplementedException ();
126                 }
127         }
128 }
129