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