Пример #1
0
        public ProtoFile(string fileName, CompletionPorts.CompletionPortSafeHandle completionPort, ConcurrentQueue <IntPtr> overlappedStructs)
        {
            _overlappedStructs = overlappedStructs;
            _fileName          = fileName;

            _fileHandle = CreateFileW(fileName, FileAccess.GENERIC_READ, System.IO.FileShare.Read,
                                      IntPtr.Zero, System.IO.FileMode.Open, FileFlag.OVERLAPPED, IntPtr.Zero);
            if (_fileHandle.IsInvalid)
            {
                var error = Marshal.GetLastWin32Error();
                throw new System.IO.FileLoadException($"Unable to load the file {fileName} with error code {error}");
            }

            _portHandle = CompletionPorts.CreateIoCompletionPort(_fileHandle.DangerousGetHandle(), completionPort.DangerousGetHandle(),
                                                                 UIntPtr.Zero, (uint)Environment.ProcessorCount);
            if (_portHandle.IsInvalid)
            {
                var error = Marshal.GetLastWin32Error();
                throw new System.IO.FileLoadException($"Unable to map to the completion port for the file {fileName} with error code {error}");
            }
        }
Пример #2
0
        public AsyncBlockCacheFile(string fileName, int blockCount, FileIdentifier id, AsyncBlockCache cache)
        {
            _cache    = cache;
            _blocks   = new AsyncBlockManager[blockCount];
            _fileName = fileName;
            _id       = id;

            _fileHandle = CreateFileW(fileName, FileAccess.GENERIC_READ, System.IO.FileShare.Read,
                                      IntPtr.Zero, System.IO.FileMode.Open, FileFlag.OVERLAPPED, IntPtr.Zero);
            if (_fileHandle.IsInvalid)
            {
                var error = Marshal.GetLastWin32Error();
                throw new System.IO.FileLoadException($"Unable to load the file {fileName} with error code {error}");
            }

            _cpHandle = CompletionPorts.CreateIoCompletionPort(_fileHandle.DangerousGetHandle(), _cache.CompletionPort.DangerousGetHandle(),
                                                               UIntPtr.Zero, (uint)Environment.ProcessorCount);
            if (_cpHandle.IsInvalid)
            {
                var error = Marshal.GetLastWin32Error();
                throw new System.IO.FileLoadException($"Unable to map to the completion port for the file {fileName} with error code {error}");
            }
        }