[sgen] Fix printf-like format warnings
[mono.git] / mcs / class / System.Core / System.IO.Pipes / NamedPipeClientStream.cs
1 //
2 // NamedPipeClientStream.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2009 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if !BOOTSTRAP_BASIC
30
31 using System;
32 using System.ComponentModel;
33 using System.IO;
34 using System.Linq;
35 using System.Runtime.InteropServices;
36 using System.Security.AccessControl;
37 using System.Security.Permissions;
38 using System.Security.Principal;
39 using System.Text;
40 using System.Threading;
41 using System.Threading.Tasks;
42 using Microsoft.Win32;
43 using Microsoft.Win32.SafeHandles;
44
45 namespace System.IO.Pipes
46 {
47         [MonoTODO ("working only on win32 right now")]
48         [HostProtection (SecurityAction.LinkDemand, MayLeakOnAbort = true)]
49         public sealed class NamedPipeClientStream : PipeStream
50         {
51                 public NamedPipeClientStream (string pipeName)
52                         : this (".", pipeName)
53                 {
54                 }
55
56                 public NamedPipeClientStream (string serverName, string pipeName)
57                         : this (serverName, pipeName, PipeDirection.InOut)
58                 {
59                 }
60
61                 public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction)
62                         : this (serverName, pipeName, direction, PipeOptions.None)
63                 {
64                 }
65
66                 public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction, PipeOptions options)
67                         : this (serverName, pipeName, direction, options, TokenImpersonationLevel.None)
68                 {
69                 }
70
71                 public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction, PipeOptions options, TokenImpersonationLevel impersonationLevel)
72                         : this (serverName, pipeName, direction, options, impersonationLevel, HandleInheritability.None)
73                 {
74                 }
75
76                 public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction, PipeOptions options, TokenImpersonationLevel impersonationLevel, HandleInheritability inheritability)
77 #if MOBILE
78                         : base (direction, DefaultBufferSize)
79                 {
80                         throw new NotImplementedException ();
81                 }
82 #else
83                         : this (serverName, pipeName, ToAccessRights (direction), options, impersonationLevel, inheritability)
84                 {
85                 }
86 #endif
87
88                 public NamedPipeClientStream (PipeDirection direction, bool isAsync, bool isConnected, SafePipeHandle safePipeHandle)
89                         : base (direction, DefaultBufferSize)
90                 {
91 #if MOBILE
92                         throw new NotImplementedException ();
93 #else
94                         if (IsWindows)
95                                 impl = new Win32NamedPipeClient (this, safePipeHandle);
96                         else
97                                 impl = new UnixNamedPipeClient (this, safePipeHandle);
98                         IsConnected = isConnected;
99                         InitializeHandle (safePipeHandle, true, isAsync);
100 #endif
101                 }
102
103                 public NamedPipeClientStream (string serverName, string pipeName, PipeAccessRights desiredAccessRights, PipeOptions options, TokenImpersonationLevel impersonationLevel, HandleInheritability inheritability)
104                         : base (ToDirection (desiredAccessRights), DefaultBufferSize)
105                 {
106                         if (impersonationLevel != TokenImpersonationLevel.None ||
107                             inheritability != HandleInheritability.None)
108                                 throw ThrowACLException ();
109 #if MOBILE
110                         throw new NotImplementedException ();
111 #else
112                         if (IsWindows)
113                                 impl = new Win32NamedPipeClient (this, serverName, pipeName, desiredAccessRights, options, inheritability);
114                         else
115                                 impl = new UnixNamedPipeClient (this, serverName, pipeName, desiredAccessRights, options, inheritability);
116 #endif
117
118                 }
119
120                 ~NamedPipeClientStream () {
121                         Dispose (false);
122                 }
123                 
124                 INamedPipeClient impl;
125
126                 public void Connect ()
127                 {
128 #if MOBILE
129                         throw new NotImplementedException ();
130 #else
131                         impl.Connect ();
132                         InitializeHandle (impl.Handle, false, impl.IsAsync);
133                         IsConnected = true;
134 #endif
135                 }
136
137                 public void Connect (int timeout)
138                 {
139 #if MOBILE
140                         throw new NotImplementedException ();
141 #else                   
142                         impl.Connect (timeout);
143                         InitializeHandle (impl.Handle, false, impl.IsAsync);
144                         IsConnected = true;
145 #endif
146                 }
147
148                 public Task ConnectAsync ()
149                 {
150                         return ConnectAsync (Timeout.Infinite, CancellationToken.None);
151                 }
152
153                 public Task ConnectAsync (int timeout)
154                 {
155                         return ConnectAsync (timeout, CancellationToken.None);
156                 }
157
158                 public Task ConnectAsync (CancellationToken cancellationToken)
159                 {
160                         return ConnectAsync (Timeout.Infinite, cancellationToken);
161                 }
162
163                 public Task ConnectAsync (int timeout, CancellationToken cancellationToken)
164                 {
165                         throw new NotImplementedException ();
166                 }
167
168                 protected override internal void CheckPipePropertyOperations () {
169                         base.CheckPipePropertyOperations();
170                 }
171
172                 public int NumberOfServerInstances {
173                         get {
174                                 CheckPipePropertyOperations ();
175                                 return impl.NumberOfServerInstances;
176                         }
177                 }
178         }
179 }
180
181 #endif