コード例 #1
0
        /// <inheritdoc/>
        protected override void Dispose(bool disposing)
        {
            // dispose the NetworkStream first, in case the event args are currently in use.
            base.Dispose(disposing);

            if (disposing)
            {
                _gatheredWriteEventArgs?.Dispose();
            }
        }
コード例 #2
0
        /// <summary>
        /// Closes the underlying socket
        /// </summary>
        /// <param name="disposing">
        /// If true, the EventArg objects will be disposed instead of being re-added to
        /// the IO pool. This should NEVER be set to true unless we are shutting down the server!
        /// </param>
        private void Dispose(bool disposeEventArgs = false)
        {
            // Set that the socket is being closed once, and properly
            if (SocketClosed)
            {
                return;
            }
            SocketClosed = true;


            ReadEventArgs.Dispose();
            WriteEventArgs.Dispose();
            DisposedEventArgs = true;
            //// Do a shutdown before you close the socket
            //try
            //{
            //    Connection.Shutdown(SocketShutdown.Both);
            //}
            //catch (Exception) { }
            //finally
            //{
            //    // Unregister for vents
            //    ReadEventArgs.Completed -= IOComplete;
            //    WriteEventArgs.Completed -= IOComplete;

            //    // Close the connection
            //    Connection.Close();
            //    Connection = null;
            //}

            //// Call Disconnect Event
            //if (!DisconnectEventCalled && OnDisconnected != null)
            //{
            //    DisconnectEventCalled = true;
            //    OnDisconnected();
            //}

            //// If we need to dispose out EventArgs
            //if (disposeEventArgs)
            //{
            //    ReadEventArgs.Dispose();
            //    WriteEventArgs.Dispose();
            //    DisposedEventArgs = true;
            //}
            //else
            //{
            //    // Finally, release this stream so we can allow a new connection
            //    SocketManager.Release(this);
            //    Released = true;
            //}
        }
コード例 #3
0
ファイル: TCPStream.cs プロジェクト: jamieb452/RetroSpyServer
        /// <summary>
        /// Closes the underlying socket
        /// </summary>
        /// <param name="DisposeEventArgs">
        /// If true, the EventArg objects will be disposed instead of being re-added to
        /// the IO pool. This should NEVER be set to true unless we are shutting down the server!
        /// </param>
        public void Close(bool DisposeEventArgs = false)
        {
            // Set that the socket is being closed once, and properly
            if (SocketClosed)
            {
                return;
            }
            SocketClosed = true;

            // Do a shutdown before you close the socket
            try
            {
                Connection.Shutdown(SocketShutdown.Both);
            }
            catch (Exception) { }
            finally
            {
                // Unregister for vents
                ReadEventArgs.Completed  -= IOComplete;
                WriteEventArgs.Completed -= IOComplete;

                // Close the connection
                Connection.Close();
                Connection = null;
            }

            // If we need to dispose out EventArgs
            if (DisposeEventArgs)
            {
                ReadEventArgs.Dispose();
                WriteEventArgs.Dispose();
                DisposedEventArgs = true;
            }
            else
            {
                // Finally, release this stream so we can allow a new connection
                SocketManager.Release(this);
                Released = true;
            }

            // Call Disconnect Event
            if (!DisconnectEventCalled && OnDisconnect != null)
            {
                DisconnectEventCalled = true;
                OnDisconnect(this);
            }
        }