PageRenderTime 46ms CodeModel.GetById 11ms RepoModel.GetById 13ms app.codeStats 0ms

/mcs/class/System.Core/System.IO.Pipes/NamedPipeClientStream.cs

https://bitbucket.org/steenlund/mono-2.6.7-for-amiga
C# | 123 lines | 83 code | 13 blank | 27 comment | 5 complexity | cd824123554f865a78db70c733f44f0d MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, LGPL-2.1
  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. using System;
  29. using System.ComponentModel;
  30. using System.IO;
  31. using System.Linq;
  32. using System.Runtime.InteropServices;
  33. using System.Security.AccessControl;
  34. using System.Security.Permissions;
  35. using System.Security.Principal;
  36. using System.Text;
  37. using Microsoft.Win32;
  38. using Microsoft.Win32.SafeHandles;
  39. namespace System.IO.Pipes
  40. {
  41. [MonoTODO ("working only on win32 right now")]
  42. [HostProtection (SecurityAction.LinkDemand, MayLeakOnAbort = true)]
  43. public sealed class NamedPipeClientStream : PipeStream
  44. {
  45. public NamedPipeClientStream (string pipeName)
  46. : this (".", pipeName)
  47. {
  48. }
  49. public NamedPipeClientStream (string serverName, string pipeName)
  50. : this (serverName, pipeName, PipeDirection.InOut)
  51. {
  52. }
  53. public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction)
  54. : this (serverName, pipeName, direction, PipeOptions.None)
  55. {
  56. }
  57. public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction, PipeOptions options)
  58. : this (serverName, pipeName, direction, options, TokenImpersonationLevel.None)
  59. {
  60. }
  61. public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction, PipeOptions options, TokenImpersonationLevel impersonationLevel)
  62. : this (serverName, pipeName, direction, options, impersonationLevel, HandleInheritability.None)
  63. {
  64. }
  65. public NamedPipeClientStream (string serverName, string pipeName, PipeDirection direction, PipeOptions options, TokenImpersonationLevel impersonationLevel, HandleInheritability inheritability)
  66. : this (serverName, pipeName, ToAccessRights (direction), options, impersonationLevel, inheritability)
  67. {
  68. }
  69. public NamedPipeClientStream (PipeDirection direction, bool isAsync, bool isConnected, SafePipeHandle safePipeHandle)
  70. : base (direction, DefaultBufferSize)
  71. {
  72. if (IsWindows)
  73. impl = new Win32NamedPipeClient (this, safePipeHandle);
  74. else
  75. impl = new UnixNamedPipeClient (this, safePipeHandle);
  76. IsConnected = isConnected;
  77. InitializeHandle (safePipeHandle, true, isAsync);
  78. }
  79. public NamedPipeClientStream (string serverName, string pipeName, PipeAccessRights desiredAccessRights, PipeOptions options, TokenImpersonationLevel impersonationLevel, HandleInheritability inheritability)
  80. : base (ToDirection (desiredAccessRights), DefaultBufferSize)
  81. {
  82. if (impersonationLevel != TokenImpersonationLevel.None ||
  83. inheritability != HandleInheritability.None)
  84. throw ThrowACLException ();
  85. if (IsWindows)
  86. impl = new Win32NamedPipeClient (this, serverName, pipeName, desiredAccessRights, options, inheritability);
  87. else
  88. impl = new UnixNamedPipeClient (this, serverName, pipeName, desiredAccessRights, options, inheritability);
  89. }
  90. INamedPipeClient impl;
  91. public void Connect ()
  92. {
  93. impl.Connect ();
  94. InitializeHandle (impl.Handle, false, impl.IsAsync);
  95. IsConnected = true;
  96. }
  97. public void Connect (int timeout)
  98. {
  99. impl.Connect (timeout);
  100. InitializeHandle (impl.Handle, false, impl.IsAsync);
  101. IsConnected = true;
  102. }
  103. public int NumberOfServerInstances {
  104. get {
  105. CheckPipePropertyOperations ();
  106. return impl.NumberOfServerInstances;
  107. }
  108. }
  109. }
  110. }