예제 #1
0
        /// <summary>
        /// Polls a File Descriptor for the passed in flags.
        /// </summary>
        /// <param name="fd">The descriptor to poll</param>
        /// <param name="events">The events to poll for</param>
        /// <param name="timeout">The amount of time to wait; -1 for infinite, 0 for immediate return, and a positive number is the number of milliseconds</param>
        /// <param name="triggered">The events that were returned by the poll call. May be PollEvents.POLLNONE in the case of a timeout.</param>
        /// <returns>An error or Error.SUCCESS.</returns>
        internal static unsafe Error Poll(SafeHandle fd, PollEvents events, int timeout, out PollEvents triggered)
        {
            bool gotRef = false;

            try
            {
                fd.DangerousAddRef(ref gotRef);

                var pollEvent = new PollEvent
                {
                    FileDescriptor = fd.DangerousGetHandle().ToInt32(),
                    Events         = events,
                };

                uint  unused;
                Error err = Poll(&pollEvent, 1, timeout, &unused);
                triggered = pollEvent.TriggeredEvents;
                return(err);
            }
            finally
            {
                if (gotRef)
                {
                    fd.DangerousRelease();
                }
            }
        }
예제 #2
0
        internal void Rebind(OracleConnection connection, ref bool mustRelease, ref SafeHandle handleToBind)
        {
            handleToBind = null;
            switch (this._metaType.OciType)
            {
            case OCI.DATATYPE.CLOB:
            case OCI.DATATYPE.BLOB:
            case OCI.DATATYPE.BFILE:
                OciLobLocator.SafeDispose(ref this._lobLocator);
                this._lobLocator = new OciLobLocator(connection, this._metaType.OracleType);
                handleToBind     = this._lobLocator.Descriptor;
                break;

            case OCI.DATATYPE.LONGRAW:
            case OCI.DATATYPE.LONG:
                this._rowBuffer.WriteInt32(this._lengthOffset, 0);
                this._longLength = -1;
                if (this._longBuffer != null)
                {
                    this._longBuffer.Reset();
                }
                else
                {
                    this._longBuffer = new NativeBuffer_LongColumnData();
                }
                handleToBind = this._longBuffer;
                break;
            }
            if (handleToBind != null)
            {
                handleToBind.DangerousAddRef(ref mustRelease);
                this._rowBuffer.WriteIntPtr(this._valueOffset, handleToBind.DangerousGetHandle());
            }
        }
        /// <summary>
        /// Acquires a lease on a safe handle. This method is intended to be used in the initializer of a <c>using</c>
        /// statement.
        /// </summary>
        /// <param name="handle">The <see cref="SafeHandle"/> to lease.</param>
        /// <returns>A <see cref="SafeHandleLease"/>, which must be disposed to release the resource.</returns>
        /// <exception cref="ObjectDisposedException">If the lease could not be acquired.</exception>
        public static SafeHandleLease Lease(this SafeHandle handle)
        {
            if (handle is null)
            {
                throw new ArgumentNullException(nameof(handle));
            }

            var success = false;

            try
            {
                handle.DangerousAddRef(ref success);
                if (!success)
                {
                    throw new ObjectDisposedException(handle.GetType().FullName);
                }

                return(new SafeHandleLease(handle));
            }
            catch
            {
                if (success)
                {
                    handle.DangerousRelease();
                }

                throw;
            }
        }
        public static unsafe PosixResult Read(SafeHandle handle, byte *buf, int count)
        {
            bool addedRef = false;

            try
            {
                handle.DangerousAddRef(ref addedRef);

                int     fd = handle.DangerousGetHandle().ToInt32();
                ssize_t rv;
                do
                {
                    rv = read(fd, buf, count);
                } while (rv < 0 && errno == EINTR);

                return(PosixResult.FromReturnValue(rv));
            }
            finally
            {
                if (addedRef)
                {
                    handle.DangerousRelease();
                }
            }
        }
예제 #5
0
        protected SafeNCryptHandle(IntPtr handle, SafeHandle parentHandle)
            : base(true)
        {
            if (parentHandle == null)
            {
                throw new ArgumentNullException(nameof(parentHandle));
            }
            if (parentHandle.IsClosed || parentHandle.IsInvalid)
            {
                throw new ArgumentException(SR.Argument_Invalid_SafeHandleInvalidOrClosed, nameof(parentHandle));
            }

            bool success = false;

            parentHandle.DangerousAddRef(ref success);
            _parentHandle = parentHandle;

            // Don't set the handle value until after parentHandle has been validated and persisted to a field,
            // otherwise Dispose will try to call the underlying Free function.
            SetHandle(handle);

            // But if this handle value IsInvalid then we'll never call ReleaseHandle, which leaves the parent open
            // forever.  Instead, release such a parent now.
            if (IsInvalid)
            {
                _parentHandle.DangerousRelease();
                _parentHandle = null;
            }
        }
예제 #6
0
        public static SafeHandleLease Lease(this SafeHandle handle)
        {
            RoslynDebug.AssertNotNull(handle);

            var success = false;

            try
            {
                handle.DangerousAddRef(ref success);
                if (!success)
                {
                    throw new ObjectDisposedException(handle.GetType().FullName);
                }

                return(new SafeHandleLease(handle));
            }
            catch
            {
                if (success)
                {
                    handle.DangerousRelease();
                }

                throw;
            }
        }
예제 #7
0
        static int WaitOneNative(SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
        {
#if MONOTOUCH
            if (exitContext)
            {
                throw new NotSupportedException("exitContext == true is not supported");
            }
#endif

            bool release = false;
            try {
                if (exitContext)
                {
                    SynchronizationAttribute.ExitContext();
                }

                waitableSafeHandle.DangerousAddRef(ref release);

                return(WaitOne_internal(waitableSafeHandle.DangerousGetHandle(), (int)millisecondsTimeout, exitContext));
            } finally {
                if (release)
                {
                    waitableSafeHandle.DangerousRelease();
                }

                if (exitContext)
                {
                    SynchronizationAttribute.EnterContext();
                }
            }
        }
예제 #8
0
        public static unsafe int Read(SafeHandle handle, Span <byte> span)
        {
            bool refAdded = false;

            try
            {
                handle.DangerousAddRef(ref refAdded);

                int rv;
                fixed(byte *ptr = span)
                {
                    do
                    {
                        rv = (int)read(handle.DangerousGetHandle().ToInt32(), ptr, span.Length);
                    } while (rv == -1 && errno == EINTR);
                }

                return(rv);
            }
            finally
            {
                if (refAdded)
                {
                    handle.DangerousRelease();
                }
            }
        }
예제 #9
0
        static int WaitOneNative(SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
        {
            bool release = false;

            try {
#if !DISABLE_REMOTING
                if (exitContext)
                {
                    SynchronizationAttribute.ExitContext();
                }
#endif

                waitableSafeHandle.DangerousAddRef(ref release);

                return(WaitOne_internal(waitableSafeHandle.DangerousGetHandle(), (int)millisecondsTimeout));
            } finally {
                if (release)
                {
                    waitableSafeHandle.DangerousRelease();
                }

#if !DISABLE_REMOTING
                if (exitContext)
                {
                    SynchronizationAttribute.EnterContext();
                }
#endif
            }
        }
예제 #10
0
            public SafeHandleArrayHelper(SafeHandle[] handles)
            {
                _safeHandles = new SafeHandle[handles.Length];
                _intPtrs     = new IntPtr[handles.Length];

                try
                {
                    for (int i = 0; i < handles.Length; i++)
                    {
                        SafeHandle handle  = handles[i];
                        bool       release = false;
                        handle.DangerousAddRef(ref release);
                        if (!release)
                        {
                            throw new InvalidOperationException("Unable to Add a reference to a SafeHandle");
                        }

                        _safeHandles[i] = handle;
                        _intPtrs[i]     = handle.DangerousGetHandle();
                    }
                }
                catch
                {
                    ReleaseSafeHandles();
                    throw;
                }
            }
예제 #11
0
        public static bool DuplicateHandle(HandleRef hSourceProcessHandle, SafeHandle hSourceHandle, HandleRef hTargetProcess,
                                           out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
        {
            bool release = false;

            try {
                hSourceHandle.DangerousAddRef(ref release);

                MonoIOError error;
                IntPtr      nakedTargetHandle;
                bool        ret = MonoIO.DuplicateHandle(hSourceProcessHandle.Handle, hSourceHandle.DangerousGetHandle(), hTargetProcess.Handle,
                                                         out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);

                if (error != MonoIOError.ERROR_SUCCESS)
                {
                    throw MonoIO.GetException(error);
                }

                targetHandle = new SafeWaitHandle(nakedTargetHandle, true);
                return(ret);
            } finally {
                if (release)
                {
                    hSourceHandle.DangerousRelease();
                }
            }
        }
예제 #12
0
        private SafeCreateHandle GetCertsArray(IList <SafeHandle> safeHandles)
        {
            int idx = 0;

            try
            {
                int      handlesCount = safeHandles.Count;
                IntPtr[] ptrs         = new IntPtr[handlesCount];
                for (; idx < handlesCount; idx++)
                {
                    SafeHandle handle   = safeHandles[idx];
                    bool       addedRef = false;
                    handle.DangerousAddRef(ref addedRef);
                    ptrs[idx] = handle.DangerousGetHandle();
                }

                // Creating the array has the effect of calling CFRetain() on all of the pointers, so the native
                // resource is safe even if we DangerousRelease=>ReleaseHandle them.
                SafeCreateHandle certsArray = Interop.CoreFoundation.CFArrayCreate(ptrs, (UIntPtr)ptrs.Length);
                _extraHandles.Push(certsArray);
                return(certsArray);
            }
            finally
            {
                for (idx--; idx >= 0; idx--)
                {
                    safeHandles[idx].DangerousRelease();
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Polls a File Descriptor for the passed in flags.
        /// </summary>
        /// <param name="fd">The descriptor to poll</param>
        /// <param name="events">The events to poll for</param>
        /// <param name="timeout">The amount of time to wait; -1 for infinite, 0 for immediate return, and a positive number is the number of milliseconds</param>
        /// <param name="triggered">The events that were returned by the poll call. May be PollEvents.POLLNONE in the case of a timeout.</param>
        /// <returns>An error or Error.SUCCESS.</returns>
        internal static unsafe Error Poll(SafeHandle fd, PollEvents events, int timeout, out PollEvents triggered)
        {
            bool gotRef = false;
            try
            {
                fd.DangerousAddRef(ref gotRef);

                var pollEvent = new PollEvent
                {
                    FileDescriptor = fd.DangerousGetHandle().ToInt32(),
                    Events = events,
                };

                uint unused;
                Error err = Poll(&pollEvent, 1, timeout, &unused);
                triggered = pollEvent.TriggeredEvents;
                return err;
            }
            finally
            {
                if (gotRef)
                {
                    fd.DangerousRelease();
                }
            }
        }
예제 #14
0
        public static bool BindHandle(SafeHandle osHandle)
        {
            if (osHandle == null)
            {
                throw new ArgumentNullException(nameof(osHandle));
            }

            bool ret = false;
            bool mustReleaseSafeHandle = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                osHandle.DangerousAddRef(ref mustReleaseSafeHandle);
                ret = BindIOCompletionCallbackNative(osHandle.DangerousGetHandle());
            }
            finally
            {
                if (mustReleaseSafeHandle)
                {
                    osHandle.DangerousRelease();
                }
            }
            return(ret);
        }
예제 #15
0
        /// <summary>
        /// Acquires a lease on a safe handle. The lease increments the reference count of the <see cref="SafeHandle"/>
        /// to ensure the handle is not released prior to the lease being released.
        /// </summary>
        /// <remarks>
        /// This method is intended to be used in the initializer of a <c>using</c> statement. Failing to release the
        /// lease will permanently prevent the underlying <see cref="SafeHandle"/> from being released by the garbage
        /// collector.
        /// </remarks>
        /// <param name="handle">The <see cref="SafeHandle"/> to lease.</param>
        /// <returns>A <see cref="SafeHandleLease"/>, which must be disposed to release the resource.</returns>
        /// <exception cref="ObjectDisposedException">If the lease could not be acquired.</exception>
        public static SafeHandleLease Lease(this SafeHandle handle)
        {
            RoslynDebug.AssertNotNull(handle);

            var success = false;

            try
            {
                handle.DangerousAddRef(ref success);
                Debug.Assert(
                    success,
                    $"{nameof(SafeHandle.DangerousAddRef)} does not return when {nameof(success)} is false."
                    );

                return(new SafeHandleLease(handle));
            }
            catch
            {
                if (success)
                {
                    handle.DangerousRelease();
                }

                throw;
            }
        }
        public static bool BindHandle(SafeHandle osHandle)
        {
            ArgumentNullException.ThrowIfNull(osHandle);

            bool mustReleaseSafeHandle = false;

            try
            {
                osHandle.DangerousAddRef(ref mustReleaseSafeHandle);

                if (UsePortableThreadPoolForIO)
                {
                    PortableThreadPool.ThreadPoolInstance.RegisterForIOCompletionNotifications(osHandle.DangerousGetHandle());
                    return(true);
                }

                return(BindIOCompletionCallbackNative(osHandle.DangerousGetHandle()));
            }
            finally
            {
                if (mustReleaseSafeHandle)
                {
                    osHandle.DangerousRelease();
                }
            }
        }
예제 #17
0
        /// <summary>
        /// Acquires a lease on a safe handle. The lease increments the reference count of the <see cref="SafeHandle"/>
        /// to ensure the handle is not released prior to the lease being released.
        /// </summary>
        /// <remarks>
        /// This method is intended to be used in the initializer of a <c>using</c> statement. Failing to release the
        /// lease will permanently prevent the underlying <see cref="SafeHandle"/> from being released by the garbage
        /// collector.
        /// </remarks>
        /// <param name="handle">The <see cref="SafeHandle"/> to lease.</param>
        /// <returns>A <see cref="SafeHandleLease"/>, which must be disposed to release the resource.</returns>
        /// <exception cref="ObjectDisposedException">If the lease could not be acquired.</exception>
        public static SafeHandleLease Lease(this SafeHandle handle)
        {
            if (handle is null)
            {
                throw new ArgumentNullException(nameof(handle));
            }

            var success = false;

            try
            {
                handle.DangerousAddRef(ref success);
                Debug.Assert(success, $"'{nameof(SafeHandle.DangerousAddRef)}' does not return when '{nameof(success)}' is false.");

                return(new SafeHandleLease(handle));
            }
            catch
            {
                if (success)
                {
                    handle.DangerousRelease();
                }

                throw;
            }
        }
예제 #18
0
        internal void SetParent(SafeHandle parent)
        {
            bool addedRef = false;

            parent.DangerousAddRef(ref addedRef);
            Debug.Assert(addedRef);

            _parent = parent;
        }
예제 #19
0
        // We rely on the reference source implementation of WaitHandle, and it delegates to a function named
        //  WaitOneNative to perform the actual operation of waiting on a handle.
        // This native operation actually has to call back into managed code and invoke .Wait
        //  on the current SynchronizationContext. As such, our implementation of this "native" method
        //  is actually managed code, and the real native icall being used is Wait_internal.
        static int WaitOneNative(SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
        {
            bool release = false;

#if !MONODROID
            var context = SynchronizationContext.Current;
#endif
            try {
                waitableSafeHandle.DangerousAddRef(ref release);

#if !DISABLE_REMOTING
                if (exitContext)
                {
                    SynchronizationAttribute.ExitContext();
                }
#endif

#if !MONODROID
                // HACK: Documentation (and public posts by experts like Joe Duffy) suggests that
                //  users must first call SetWaitNotificationRequired to flag that a given synchronization
                //  context overrides .Wait. Because invoking the Wait method is somewhat expensive, we use
                //  the notification-required flag to determine whether or not we should invoke the managed
                //  wait method.
                // Another option would be to check whether this context uses the default Wait implementation,
                //  but I don't know of a cheap way to do this that handles derived types correctly.
                // If the thread does not have a synchronization context set at all, we can safely just
                //  jump directly to invoking Wait_internal.
                if ((context != null) && context.IsWaitNotificationRequired())
                {
                    return(context.Wait(
                               new IntPtr[] { waitableSafeHandle.DangerousGetHandle() },
                               false,
                               (int)millisecondsTimeout
                               ));
                }
                else
#endif
                {
                    unsafe {
                        IntPtr handle = waitableSafeHandle.DangerousGetHandle();
                        return(Wait_internal(&handle, 1, false, (int)millisecondsTimeout));
                    }
                }
            } finally {
                if (release)
                {
                    waitableSafeHandle.DangerousRelease();
                }

#if !DISABLE_REMOTING
                if (exitContext)
                {
                    SynchronizationAttribute.EnterContext();
                }
#endif
            }
        }
예제 #20
0
파일: ChainPal.cs 프로젝트: yuzexun/corefx
        private SafeCreateHandle PrepareCertsArray(ICertificatePal cert, X509Certificate2Collection extraStore)
        {
            IntPtr[]     ptrs        = new IntPtr[1 + (extraStore?.Count ?? 0)];
            SafeHandle[] safeHandles = new SafeHandle[ptrs.Length];

            AppleCertificatePal applePal = (AppleCertificatePal)cert;

            safeHandles[0] = applePal.CertificateHandle;

            if (extraStore != null)
            {
                for (int i = 0; i < extraStore.Count; i++)
                {
                    AppleCertificatePal extraCertPal = (AppleCertificatePal)extraStore[i].Pal;

                    safeHandles[i + 1] = extraCertPal.CertificateHandle;
                }
            }

            int  idx      = 0;
            bool addedRef = false;

            try
            {
                for (idx = 0; idx < safeHandles.Length; idx++)
                {
                    SafeHandle handle = safeHandles[idx];
                    handle.DangerousAddRef(ref addedRef);
                    ptrs[idx] = handle.DangerousGetHandle();
                }
            }
            catch
            {
                // If any DangerousAddRef failed, idx will be on the one that failed, so we'll start off
                // by subtracing one.
                for (idx--; idx >= 0; idx--)
                {
                    safeHandles[idx].DangerousRelease();
                }

                throw;
            }

            // Creating the array has the effect of calling CFRetain() on all of the pointers, so the native
            // resource is safe even if we DangerousRelease=>ReleaseHandle them.
            SafeCreateHandle certsArray = Interop.CoreFoundation.CFArrayCreate(ptrs, (UIntPtr)ptrs.Length);

            _extraHandles.Push(certsArray);

            for (idx = 0; idx < safeHandles.Length; idx++)
            {
                safeHandles[idx].DangerousRelease();
            }

            return(certsArray);
        }
예제 #21
0
        //-------------------------------------------------------
        // SafeHandle Helpers
        //-------------------------------------------------------

        // AddRefs the SH and returns the underlying unmanaged handle.
        internal static IntPtr SafeHandleAddRef(SafeHandle pHandle, ref bool success)
        {
            if (pHandle == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pHandle, ExceptionResource.ArgumentNull_SafeHandle);
            }

            pHandle.DangerousAddRef(ref success);
            return(pHandle.DangerousGetHandle());
        }
예제 #22
0
        internal void TransferOwnershipToParent(SafeHandle parent)
        {
            Debug.Assert(_parent == null, "Expected no existing parent");
            Debug.Assert(parent != null && !parent.IsInvalid, "Expected new parent to be non-null and valid");

            bool addedRef = false;
            parent.DangerousAddRef(ref addedRef);

            _parent = parent;
        }
            public IOUringAsyncContext(IOUringThread thread, SafeHandle handle)
            {
                _iouring    = thread;
                _writeQueue = new Queue(thread, this);
                _readQueue  = new Queue(thread, this);
                bool success = false;

                handle.DangerousAddRef(ref success);
                _fd     = handle.DangerousGetHandle().ToInt32();
                _handle = handle;
            }
예제 #24
0
        internal SafePipeHandle(Socket namedPipeSocket) : base(ownsHandle: true)
        {
            Debug.Assert(namedPipeSocket != null);
            _namedPipeSocket = namedPipeSocket;

            _namedPipeSocketHandle = namedPipeSocket.SafeHandle;

            bool ignored = false;

            _namedPipeSocketHandle.DangerousAddRef(ref ignored);
            SetHandle(_namedPipeSocketHandle.DangerousGetHandle());
        }
        internal static string?GetAuthenticationPackageName(SafeHandle safeHandle, int negotiationState)
        {
            if (safeHandle.IsInvalid)
            {
                if (NetEventSource.Log.IsEnabled())
                {
                    NetEventSource.Info(null, $"Invalid handle:{safeHandle}");
                }
                return(null);
            }

            bool gotRef = false;

            try
            {
                safeHandle.DangerousAddRef(ref gotRef);
                IntPtr packageInfo = safeHandle.DangerousGetHandle();
                if (NetEventSource.Log.IsEnabled())
                {
                    NetEventSource.Info(null, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x}");
                }

                if (negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_COMPLETE ||
                    negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_OPTIMISTIC)
                {
                    string?name;
                    unsafe
                    {
                        name = Marshal.PtrToStringUni(((SecurityPackageInfo *)packageInfo)->Name);
                    }

                    if (NetEventSource.Log.IsEnabled())
                    {
                        NetEventSource.Info(null, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x} name:{name}");
                    }

                    // An optimization for future string comparisons.
                    return
                        (string.Equals(name, Kerberos, StringComparison.OrdinalIgnoreCase) ? Kerberos :
                         string.Equals(name, NTLM, StringComparison.OrdinalIgnoreCase) ? NTLM :
                         name);
                }
            }
            finally
            {
                if (gotRef)
                {
                    safeHandle.DangerousRelease();
                }
            }

            return(null);
        }
예제 #26
0
        public IntPtr MarshalManagedToNative(object ManagedObj)
        {
            if (ManagedObj == null)
            {
                return(IntPtr.Zero);
            }

            var  array   = (SafeHandle[])ManagedObj;
            int  i       = 0;
            bool success = false;

            try
            {
                for (i = 0; i < array.Length; success = false, i++)
                {
                    SafeHandle current = array[i];
                    if (current != null && !current.IsClosed && !current.IsInvalid)
                    {
                        current.DangerousAddRef(ref success);
                    }
                }

                IntPtr result = Marshal.AllocHGlobal((array.Length + 1) * IntPtr.Size);
                Marshal.WriteIntPtr(result, 0, GCHandle.ToIntPtr(GCHandle.Alloc(array, GCHandleType.Normal)));
                for (int j = 0; j < array.Length; j++)
                {
                    SafeHandle current = array[j];
                    if (current == null || current.IsClosed || current.IsInvalid)
                    {
                        // the memory for this element was initialized to null by AllocHGlobal
                        continue;
                    }

                    Marshal.WriteIntPtr(result, (j + 1) * IntPtr.Size, current.DangerousGetHandle());
                }

                return(result + IntPtr.Size);
            }
            catch
            {
                int total = success ? i + 1 : i;
                for (int j = 0; j < total; j++)
                {
                    SafeHandle current = array[j];
                    if (current != null)
                    {
                        current.DangerousRelease();
                    }
                }

                throw;
            }
        }
예제 #27
0
            public IOUringAsyncContext(IOUringThread thread, SafeHandle handle)
            {
                _iouring    = thread;
                _writeQueue = new Queue(thread, this, readNotWrite: false);
                _readQueue  = new Queue(thread, this, readNotWrite: true);
                bool success = false;

                handle.DangerousAddRef(ref success);
                _fd     = handle.DangerousGetHandle().ToInt32();
                _handle = handle;
                SocketPal.SetNonBlocking(handle);
            }
            public EPollAsyncContext(EPollThread thread, SafeHandle handle)
            {
                _epoll      = thread;
                _writeQueue = new Queue(thread);
                _readQueue  = new Queue(thread);
                bool success = false;

                handle.DangerousAddRef(ref success);
                _fd     = handle.DangerousGetHandle().ToInt32();
                _handle = handle;

                _epoll.Control(EPOLL_CTL_ADD, _fd, EPOLLIN | EPOLLOUT | EPOLLET, Key);
            }
        internal SafeProvOrNCryptKeyHandleUwp(IntPtr handle, SafeHandle parentHandle)
            : this(handle, true, true)
        {
            Debug.Assert(parentHandle != null && !parentHandle.IsClosed && !parentHandle.IsInvalid);

            // If the provided handle value wasn't valid we won't call dispose, so we shouldn't be doing this.
            Debug.Assert(!IsInvalid);

            bool addedRef = false;

            parentHandle.DangerousAddRef(ref addedRef);
            _parentHandle = parentHandle;
        }
 internal static IntPtr SafeHandleAddRef(SafeHandle pHandle, ref bool success)
 {
     if (pHandle == null)
     {
         throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_SafeHandle"));
     }
     pHandle.DangerousAddRef(ref success);
     if (!success)
     {
         return(IntPtr.Zero);
     }
     return(pHandle.DangerousGetHandle());
 }
예제 #31
0
파일: MonoIO.cs 프로젝트: Tsalex71/mono-1
        public static MonoFileType GetFileType(SafeHandle safeHandle, out MonoIOError error)
        {
            bool release = false;

            try {
                safeHandle.DangerousAddRef(ref release);
                return(GetFileType(safeHandle.DangerousGetHandle(), out error));
            } finally {
                if (release)
                {
                    safeHandle.DangerousRelease();
                }
            }
        }
예제 #32
0
 internal static unsafe Error GetIPv6MulticastOption(SafeHandle socket, MulticastOption multicastOption, IPv6MulticastOption* option)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousGetIPv6MulticastOption((int)socket.DangerousGetHandle(), multicastOption, option);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #33
0
 internal static unsafe Error Accept(SafeHandle socket, byte* socketAddress, int* socketAddressLen, int* acceptedFd)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousAccept((int)socket.DangerousGetHandle(), socketAddress, socketAddressLen, acceptedFd);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #34
0
 internal static Error TryChangeSocketEventRegistration(int port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousTryChangeSocketEventRegistration(port, (int)socket.DangerousGetHandle(), currentEvents, newEvents, data);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #35
0
 internal static Error Shutdown(SafeHandle socket, SocketShutdown how)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousShutdown((int)socket.DangerousGetHandle(), how);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #36
0
 internal static unsafe Error GetBytesAvailable(SafeHandle socket, int* available)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousGetBytesAvailable((int)socket.DangerousGetHandle(), available);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #37
0
 internal static unsafe Error SetReceiveTimeout(SafeHandle socket, int millisecondsTimeout)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousSetReceiveTimeout((int)socket.DangerousGetHandle(), millisecondsTimeout);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #38
0
 internal static unsafe Error GetSockName(SafeHandle socket, byte* socketAddress, int* socketAddressLen)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousGetSockName((int)socket.DangerousGetHandle(), socketAddress, socketAddressLen);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #39
0
 internal static unsafe Error SetSockOpt(SafeHandle socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int optionLen)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousSetSockOpt((int)socket.DangerousGetHandle(), optionLevel, optionName, optionValue, optionLen);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #40
0
 internal static unsafe Error SendMessage(SafeHandle socket, MessageHeader* messageHeader, SocketFlags flags, long* sent)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousSendMessage((int)socket.DangerousGetHandle(), messageHeader, flags, sent);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #41
0
 internal static unsafe Error GetSocketErrorOption(SafeHandle socket, Error* socketError)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousGetSocketErrorOption((int)socket.DangerousGetHandle(), socketError);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
예제 #42
0
 internal static Error Listen(SafeHandle socket, int backlog)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousListen((int)socket.DangerousGetHandle(), backlog);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }