2 // NamedPipeClientStream.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2009 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
32 using System.ComponentModel;
35 using System.Runtime.InteropServices;
36 using System.Security.AccessControl;
37 using System.Security.Permissions;
38 using System.Security.Principal;
40 using System.Threading;
41 using System.Threading.Tasks;
42 using Microsoft.Win32;
43 using Microsoft.Win32.SafeHandles;
45 namespace System.IO.Pipes
47 [MonoTODO ("working only on win32 right now")]
48 [HostProtection (SecurityAction.LinkDemand, MayLeakOnAbort = true)]
49 public sealed class NamedPipeClientStream : PipeStream
51 public NamedPipeClientStream (string pipeName)
52 : this (".", pipeName)
56 public NamedPipeClientStream (string serverName, string pipeName)
57 : this (serverName, pipeName, PipeDirection.InOut)
61 public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction)
62 : this (serverName, pipeName, direction, PipeOptions.None)
66 public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction, PipeOptions options)
67 : this (serverName, pipeName, direction, options, TokenImpersonationLevel.None)
71 public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction, PipeOptions options, TokenImpersonationLevel impersonationLevel)
72 : this (serverName, pipeName, direction, options, impersonationLevel, HandleInheritability.None)
76 public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction, PipeOptions options, TokenImpersonationLevel impersonationLevel, HandleInheritability inheritability)
78 : base (direction, DefaultBufferSize)
80 throw new NotImplementedException ();
83 : this (serverName, pipeName, ToAccessRights (direction), options, impersonationLevel, inheritability)
88 public NamedPipeClientStream (PipeDirection direction, bool isAsync, bool isConnected, SafePipeHandle safePipeHandle)
89 : base (direction, DefaultBufferSize)
92 throw new NotImplementedException ();
95 impl = new Win32NamedPipeClient (this, safePipeHandle);
97 impl = new UnixNamedPipeClient (this, safePipeHandle);
98 IsConnected = isConnected;
99 InitializeHandle (safePipeHandle, true, isAsync);
103 public NamedPipeClientStream (string serverName, string pipeName, PipeAccessRights desiredAccessRights, PipeOptions options, TokenImpersonationLevel impersonationLevel, HandleInheritability inheritability)
104 : base (ToDirection (desiredAccessRights), DefaultBufferSize)
106 if (impersonationLevel != TokenImpersonationLevel.None ||
107 inheritability != HandleInheritability.None)
108 throw ThrowACLException ();
110 throw new NotImplementedException ();
113 impl = new Win32NamedPipeClient (this, serverName, pipeName, desiredAccessRights, options, inheritability);
115 impl = new UnixNamedPipeClient (this, serverName, pipeName, desiredAccessRights, options, inheritability);
120 ~NamedPipeClientStream () {
124 INamedPipeClient impl;
126 public void Connect ()
129 throw new NotImplementedException ();
132 InitializeHandle (impl.Handle, false, impl.IsAsync);
137 public void Connect (int timeout)
140 throw new NotImplementedException ();
142 impl.Connect (timeout);
143 InitializeHandle (impl.Handle, false, impl.IsAsync);
148 public Task ConnectAsync ()
150 return ConnectAsync (Timeout.Infinite, CancellationToken.None);
153 public Task ConnectAsync (int timeout)
155 return ConnectAsync (timeout, CancellationToken.None);
158 public Task ConnectAsync (CancellationToken cancellationToken)
160 return ConnectAsync (Timeout.Infinite, cancellationToken);
163 public Task ConnectAsync (int timeout, CancellationToken cancellationToken)
165 throw new NotImplementedException ();
168 protected override internal void CheckPipePropertyOperations () {
169 base.CheckPipePropertyOperations();
172 public int NumberOfServerInstances {
174 CheckPipePropertyOperations ();
175 return impl.NumberOfServerInstances;