flush
[mcs.git] / class / System.Core / System.IO.Pipes / NamedPipeClientStream.cs
blob357f7387d23681febef3fbd4bf1bc440688d6c43
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.
29 #if !BOOTSTRAP_BASIC
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 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)
82 if (IsWindows)
83 impl = new Win32NamedPipeClient (this, safePipeHandle);
84 else
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 ();
97 if (IsWindows)
98 impl = new Win32NamedPipeClient (this, serverName, pipeName, desiredAccessRights, options, inheritability);
99 else
100 impl = new UnixNamedPipeClient (this, serverName, pipeName, desiredAccessRights, options, inheritability);
103 INamedPipeClient impl;
105 public void Connect ()
107 impl.Connect ();
108 InitializeHandle (impl.Handle, false, impl.IsAsync);
109 IsConnected = true;
112 public void Connect (int timeout)
114 impl.Connect (timeout);
115 InitializeHandle (impl.Handle, false, impl.IsAsync);
116 IsConnected = true;
119 public int NumberOfServerInstances {
120 get {
121 CheckPipePropertyOperations ();
122 return impl.NumberOfServerInstances;
128 #endif