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 Microsoft
.Win32
;
41 using Microsoft
.Win32
.SafeHandles
;
43 namespace System
.IO
.Pipes
45 [MonoTODO ("working only on win32 right now")]
46 [HostProtection (SecurityAction
.LinkDemand
, MayLeakOnAbort
= true)]
47 public sealed class NamedPipeClientStream
: PipeStream
49 public NamedPipeClientStream (string pipeName
)
50 : this (".", pipeName
)
54 public NamedPipeClientStream (string serverName
, string pipeName
)
55 : this (serverName
, pipeName
, PipeDirection
.InOut
)
59 public NamedPipeClientStream (string serverName
, string pipeName
, PipeDirection direction
)
60 : this (serverName
, pipeName
, direction
, PipeOptions
.None
)
64 public NamedPipeClientStream (string serverName
, string pipeName
, PipeDirection direction
, PipeOptions options
)
65 : this (serverName
, pipeName
, direction
, options
, TokenImpersonationLevel
.None
)
69 public NamedPipeClientStream (string serverName
, string pipeName
, PipeDirection direction
, PipeOptions options
, TokenImpersonationLevel impersonationLevel
)
70 : this (serverName
, pipeName
, direction
, options
, impersonationLevel
, HandleInheritability
.None
)
74 public NamedPipeClientStream (string serverName
, string pipeName
, PipeDirection direction
, PipeOptions options
, TokenImpersonationLevel impersonationLevel
, HandleInheritability inheritability
)
75 : this (serverName
, pipeName
, ToAccessRights (direction
), options
, impersonationLevel
, inheritability
)
79 public NamedPipeClientStream (PipeDirection direction
, bool isAsync
, bool isConnected
, SafePipeHandle safePipeHandle
)
80 : base (direction
, DefaultBufferSize
)
83 impl
= new Win32NamedPipeClient (this, safePipeHandle
);
85 impl
= new UnixNamedPipeClient (this, safePipeHandle
);
86 IsConnected
= isConnected
;
87 InitializeHandle (safePipeHandle
, true, isAsync
);
90 public NamedPipeClientStream (string serverName
, string pipeName
, PipeAccessRights desiredAccessRights
, PipeOptions options
, TokenImpersonationLevel impersonationLevel
, HandleInheritability inheritability
)
91 : base (ToDirection (desiredAccessRights
), DefaultBufferSize
)
93 if (impersonationLevel
!= TokenImpersonationLevel
.None
||
94 inheritability
!= HandleInheritability
.None
)
95 throw ThrowACLException ();
98 impl
= new Win32NamedPipeClient (this, serverName
, pipeName
, desiredAccessRights
, options
, inheritability
);
100 impl
= new UnixNamedPipeClient (this, serverName
, pipeName
, desiredAccessRights
, options
, inheritability
);
103 INamedPipeClient impl
;
105 public void Connect ()
108 InitializeHandle (impl
.Handle
, false, impl
.IsAsync
);
112 public void Connect (int timeout
)
114 impl
.Connect (timeout
);
115 InitializeHandle (impl
.Handle
, false, impl
.IsAsync
);
119 public int NumberOfServerInstances
{
121 CheckPipePropertyOperations ();
122 return impl
.NumberOfServerInstances
;