Beispiel #1
0
        private void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                m_disposed = true;

                m_inOverlapped.Dispose();
                m_outOverlapped.Dispose();

                // for Windows XP
                if (Environment.OSVersion.Version.Major == 5)
                {
                    UnsafeMethods.CancelIo(Handle);
                }
                else
                {
                    UnsafeMethods.CancelIoEx(Handle, IntPtr.Zero);
                }

                int error = UnsafeMethods.closesocket(Handle);

                if (error != 0)
                {
                    error = Marshal.GetLastWin32Error();
                }


                if (m_remoteAddress != null)
                {
                    m_remoteAddress.Dispose();
                    m_remoteAddress = null;
                }

                if (m_boundAddress != null)
                {
                    m_boundAddress.Dispose();
                    m_boundAddress = null;
                }

                if (m_sendPinnedBuffer != null)
                {
                    m_sendPinnedBuffer.Dispose();
                    m_sendPinnedBuffer = null;
                }

                if (m_receivePinnedBuffer != null)
                {
                    m_receivePinnedBuffer.Dispose();
                    m_receivePinnedBuffer = null;
                }

                if (m_acceptSocketBufferAddress != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(m_acceptSocketBufferAddress);
                }
            }
        }
Beispiel #2
0
        private void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                m_disposed = true;

                m_inOverlapped.Dispose();
                m_outOverlapped.Dispose();

                // for Windows XP
#if NETSTANDARD1_3
                UnsafeMethods.CancelIoEx(Handle, IntPtr.Zero);
#else
                if (Environment.OSVersion.Version.Major == 5)
                {
                    UnsafeMethods.CancelIo(Handle);
                }
                else
                {
                    UnsafeMethods.CancelIoEx(Handle, IntPtr.Zero);
                }
#endif

                int error = UnsafeMethods.closesocket(Handle);

                if (error != 0)
                {
                    error = Marshal.GetLastWin32Error();
                }


                if (m_remoteAddress != null)
                {
                    m_remoteAddress.Dispose();
                    m_remoteAddress = null;
                }

                if (m_boundAddress != null)
                {
                    m_boundAddress.Dispose();
                    m_boundAddress = null;
                }

                if (m_listener != null)
                {
                    m_listener.Dispose();
                }
            }
        }
Beispiel #3
0
        private void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                m_disposed = true;

                m_inOverlapped.Dispose();
                m_outOverlapped.Dispose();

                // for Windows XP
#if NETSTANDARD1_3
                UnsafeMethods.CancelIoEx(Handle, IntPtr.Zero);
#else
                if (false)
                {
                    UnsafeMethods.CancelIo(Handle);
                }
                else
                {
                    UnsafeMethods.CancelIoEx(Handle, IntPtr.Zero);
                }
#endif

                int error = UnsafeMethods.closesocket(Handle);

                if (error != 0)
                {
                    error = Marshal.GetLastWin32Error();
                }


                if (m_remoteAddress != null)
                {
                    m_remoteAddress.Dispose();
                    m_remoteAddress = null;
                }

                if (m_boundAddress != null)
                {
                    m_boundAddress.Dispose();
                    m_boundAddress = null;
                }

                if (m_sendPinnedBuffer != null)
                {
                    m_sendPinnedBuffer.Dispose();
                    m_sendPinnedBuffer = null;
                }

                if (m_receivePinnedBuffer != null)
                {
                    m_receivePinnedBuffer.Dispose();
                    m_receivePinnedBuffer = null;
                }

                if (m_acceptSocketBufferAddress != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(m_acceptSocketBufferAddress);
                }

                if (m_acceptSocket != null)
                {
                    m_acceptSocket.Dispose();
                }
            }
        }