Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Create() [2/2]

void System.IO.Pipes.NamedPipeServerStream.Create ( string pipeName,
PipeDirection direction,
int maxNumberOfServerInstances,
PipeTransmissionMode transmissionMode,
PipeOptions options,
int inBufferSize,
int outBufferSize,
PipeSecurity pipeSecurity,
HandleInheritability inheritability,
PipeAccessRights additionalAccessRights )
inlineprivate

Definition at line 229 of file NamedPipeServerStream.cs.

230 {
231 string fullPath = Path.GetFullPath("\\\\.\\pipe\\" + pipeName);
232 if (string.Equals(fullPath, "\\\\.\\pipe\\anonymous", StringComparison.OrdinalIgnoreCase))
233 {
234 throw new ArgumentOutOfRangeException("pipeName", System.SR.ArgumentOutOfRange_AnonymousReserved);
235 }
236 if (base.IsCurrentUserOnly)
237 {
238 using (WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent())
239 {
240 SecurityIdentifier owner = windowsIdentity.Owner;
241 PipeAccessRule rule = new PipeAccessRule(owner, PipeAccessRights.FullControl, AccessControlType.Allow);
242 pipeSecurity = new PipeSecurity();
243 pipeSecurity.AddAccessRule(rule);
244 pipeSecurity.SetOwner(owner);
245 }
246 options &= ~PipeOptions.CurrentUserOnly;
247 }
248 int openMode = (int)direction | ((maxNumberOfServerInstances == 1) ? 524288 : 0) | (int)options | (int)additionalAccessRights;
249 int pipeMode = ((int)transmissionMode << 2) | ((int)transmissionMode << 1);
250 if (maxNumberOfServerInstances == -1)
251 {
252 maxNumberOfServerInstances = 255;
253 }
254 GCHandle pinningHandle = default(GCHandle);
255 try
256 {
257 global::Interop.Kernel32.SECURITY_ATTRIBUTES securityAttributes = PipeStream.GetSecAttrs(inheritability, pipeSecurity, ref pinningHandle);
258 SafePipeHandle safePipeHandle = global::Interop.Kernel32.CreateNamedPipe(fullPath, openMode, pipeMode, maxNumberOfServerInstances, outBufferSize, inBufferSize, 0, ref securityAttributes);
259 if (safePipeHandle.IsInvalid)
260 {
262 }
263 InitializeHandle(safePipeHandle, isExposed: false, (options & PipeOptions.Asynchronous) != 0);
264 }
265 finally
266 {
267 if (pinningHandle.IsAllocated)
268 {
269 pinningHandle.Free();
270 }
271 }
272 }
PipeStream(PipeDirection direction, int bufferSize)
void InitializeHandle(SafePipeHandle? handle, bool isExposed, bool isAsync)
static Exception GetExceptionForLastWin32Error(string path="")
static string ArgumentOutOfRange_AnonymousReserved
Definition SR.cs:28
Definition SR.cs:7

References System.IO.Pipes.PipeSecurity.AddAccessRule(), System.SR.ArgumentOutOfRange_AnonymousReserved, System.Runtime.InteropServices.GCHandle.Free(), System.Security.Principal.WindowsIdentity.GetCurrent(), System.IO.Win32Marshal.GetExceptionForLastWin32Error(), System.IO.Path.GetFullPath(), System.IO.Pipes.PipeStream.GetSecAttrs(), System.IO.Pipes.PipeStream.InitializeHandle(), System.Runtime.InteropServices.GCHandle.IsAllocated, Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid.IsInvalid, System.options, System.Security.Principal.WindowsIdentity.Owner, and System.Security.AccessControl.ObjectSecurity< T >.SetOwner().