示例#1
0
        // Check if there is pending Synchronous operation.
        // If so, it will also try to cancel it.
        // And it will also close the stream if safe.
        // Returns true if the stream was closed by the function.
        private bool CancelPendingIoAndCloseIfSafe(bool closeWithTimeout, int timeout)
        {
            if (TryCloseNetworkStream(closeWithTimeout, timeout))
            {
                return(true);
            }

            try {
                Socket socket = m_NetworkStream.InternalSocket;

                if (UnsafeNclNativeMethods.CancelIoEx(socket.SafeHandle, IntPtr.Zero) == 0)
                {
#if DEBUG
                    int error = Marshal.GetLastWin32Error();

                    if (error != UnsafeNclNativeMethods.ErrorCodes.ERROR_NOT_FOUND)
                    {
                        GlobalLog.Print("Socket#" + ValidationHelper.HashString(socket) + "::CancelIoEx() Result:" + error.ToString());
                    }
#endif
                }
            } catch { }

            // Try it again
            return(TryCloseNetworkStream(closeWithTimeout, timeout));
        }
示例#2
0
        internal void CancelLastWrite(CriticalHandle requestQueueHandle)
        {
            HttpResponseStreamAsyncResult asyncState = m_LastWrite;

            if (asyncState != null && !asyncState.IsCompleted)
            {
                UnsafeNclNativeMethods.CancelIoEx(requestQueueHandle, asyncState.m_pOverlapped);
            }
        }
示例#3
0
        // This function cancels pending m_AbortSocket and m_AbortSocket6 connecting sockets as needed.
        // This is only needed if we are closing before Activate() succeeded.
        // There are never IO operations on m_AbortSocket or m_AbortSocket6
        private void CloseConnectingSockets(bool useTimeout, int timeout)
        {
            Socket socket4 = m_AbortSocket;
            Socket socket6 = m_AbortSocket6;

            if (socket4 != null)
            {
                if (ServicePointManager.UseSafeSynchronousClose)
                {
                    try {
                        UnsafeNclNativeMethods.CancelIoEx(socket4.SafeHandle, IntPtr.Zero);
                    }
                    catch { }
                }

                if (useTimeout)
                {
                    socket4.Close(timeout);
                }
                else
                {
                    socket4.Close();
                }
                m_AbortSocket = null;
            }

            if (socket6 != null)
            {
                if (ServicePointManager.UseSafeSynchronousClose)
                {
                    try {
                        UnsafeNclNativeMethods.CancelIoEx(socket6.SafeHandle, IntPtr.Zero);
                    }
                    catch { }
                }

                if (useTimeout)
                {
                    socket6.Close(timeout);
                }
                else
                {
                    socket6.Close();
                }
                m_AbortSocket6 = null;
            }
        }