Exemple #1
0
        public void Dispose()
        {
            if (!_disposed.Raise())
            {
                return;
            }

            GC.SuppressFinalize(this);
            _options.IoMetrics.FileClosed(FileName.FullPath);

            List <Exception> exceptions = null;

            TryExecute(() =>
            {
                _readHandle.Dispose();
                if (_readHandle.FailCode != PalFlags.FailCodes.Success)
                {
                    PalHelper.ThrowLastError(_readHandle.FailCode, _readHandle.ErrorNo,
                                             $"Attempted to close 'read journal handle' - Path: {FileName.FullPath}");
                }
            });

            TryExecute(() =>
            {
                _writeHandle.Dispose();
                if (_writeHandle.FailCode != PalFlags.FailCodes.Success)
                {
                    PalHelper.ThrowLastError(_writeHandle.FailCode, _writeHandle.ErrorNo,
                                             $"Attempted to close 'write journal handle' - Path: {FileName.FullPath}");
                }
            });

            if (exceptions != null)
            {
                throw new AggregateException("Failed to dispose journal writer", exceptions);
            }

            if (DeleteOnClose)
            {
                _options.TryStoreJournalForReuse(FileName);
            }

            void TryExecute(Action a)
            {
                try
                {
                    a();
                }
                catch (Exception e)
                {
                    if (exceptions == null)
                    {
                        exceptions = new List <Exception>();
                    }
                    exceptions.Add(e);
                }
            }
        }
 public void Dispose()
 {
     Disposed = true;
     GC.SuppressFinalize(this);
     _options.IoMetrics.FileClosed(_filename.FullPath);
     if (_fdReads != -1)
     {
         Syscall.close(_fdReads);
         _fdReads = -1;
     }
     if (_fd != -1)
     {
         Syscall.close(_fd);
         _fd = -1;
     }
     if (DeleteOnClose)
     {
         _options.TryStoreJournalForReuse(_filename);
     }
 }
Exemple #3
0
        public void Dispose()
        {
            if (!_disposed.Raise())
            {
                return;
            }

            GC.SuppressFinalize(this);
            _options.IoMetrics.FileClosed(_filename.FullPath);
            _readHandle?.Dispose();
            _readHandle = null;
            _handle?.Dispose();
            _handle = null;
            if (_nativeOverlapped != null)
            {
                NativeMemory.Free((byte *)_nativeOverlapped, sizeof(NativeOverlapped));
                _nativeOverlapped = null;
            }

            if (DeleteOnClose)
            {
                _options.TryStoreJournalForReuse(_filename);
            }
        }