예제 #1
0
        internal static MemoryMappedDataReaderFactory CreateUnix(string filename, bool mapAsImage)
        {
            if (!canTryUnix)
            {
                return(null);
            }

            var creator = new MemoryMappedDataReaderFactory(GetFullPath(filename));

            try {
                Unix.Mmap(creator, mapAsImage);
                if (mapAsImage)                   // Only check this if we know that mmap() works, i.e., if above call succeeds
                {
                    creator.Dispose();
                    throw new ArgumentException("mapAsImage == true is not supported on this OS");
                }
                return(creator);
            }
            catch (MemoryMappedIONotSupportedException ex) {
                Debug.WriteLine($"mmap'd IO didn't work: {ex.Message}");
            }
            catch (EntryPointNotFoundException) {
            }
            catch (DllNotFoundException) {
            }
            canTryUnix = false;
            return(null);
        }
예제 #2
0
        /// <summary>
        /// Creates a new <see cref="MemoryMappedFileStreamCreator"/> if supported or returns
        /// <c>null</c> if the OS functions aren't supported.
        /// </summary>
        /// <remarks>If <paramref name="mapAsImage"/> is <c>true</c>, then the created
        /// <see cref="UnmanagedMemoryStreamCreator"/> that is used internally by the class,
        /// can only access bytes up to the file size, not to the end of the mapped image. You must
        /// set <see cref="UnmanagedMemoryStreamCreator.Length"/> to the correct image length to access the full image.</remarks>
        /// <param name="fileName">Name of the file</param>
        /// <param name="mapAsImage">NOT SUPPORTED. <c>true</c> if we should map it as an executable</param>
        /// <exception cref="IOException">If we can't open/map the file</exception>
        internal static MemoryMappedFileStreamCreator CreateUnix(string fileName, bool mapAsImage)
        {
            if (!canTryUnix)
            {
                return(null);
            }

            var creator = new MemoryMappedFileStreamCreator();

            creator.theFileName = GetFullPath(fileName);
            try {
                Unix.Mmap(creator, mapAsImage);
                if (mapAsImage)                   // Only check this if we know that mmap() works, i.e., if above call succeeds
                {
                    creator.Dispose();
                    throw new ArgumentException("mapAsImage == true is not supported on this OS");
                }
                return(creator);
            }
            catch (MemoryMappedIONotSupportedException ex) {
                Debug.WriteLine(string.Format("mmap'd IO didn't work: {0}", ex.Message));
                //TODO: The lseek() and mmap() fails on MacOS.
            }
            catch (EntryPointNotFoundException) {
            }
            catch (DllNotFoundException) {
            }
            canTryUnix = false;
            return(null);
        }
        /// <summary>
        /// Creates a new <see cref="MemoryMappedFileStreamCreator"/> if supported or returns
        /// <c>null</c> if the OS functions aren't supported.
        /// </summary>
        /// <remarks>If <paramref name="mapAsImage"/> is <c>true</c>, then the created
        /// <see cref="UnmanagedMemoryStreamCreator"/> that is used internally by the class,
        /// can only access bytes up to the file size, not to the end of the mapped image. You must
        /// set <see cref="UnmanagedMemoryStreamCreator.Length"/> to the correct image length to access the full image.</remarks>
        /// <param name="fileName">Name of the file</param>
        /// <param name="mapAsImage">NOT SUPPORTED. <c>true</c> if we should map it as an executable</param>
        /// <exception cref="IOException">If we can't open/map the file</exception>
        internal static MemoryMappedFileStreamCreator CreateUnix(string fileName, bool mapAsImage)
        {
            if (!canTryUnix)
            {
                return(null);
            }

            var creator = new MemoryMappedFileStreamCreator();

            creator.theFileName = GetFullPath(fileName);
            try {
                Unix.Mmap(creator, mapAsImage);
                if (mapAsImage)                   // Only check this if we know that mmap() works, i.e., if above call succeeds
                {
                    creator.Dispose();
                    throw new ArgumentException("mapAsImage == true is not supported on this OS");
                }
                return(creator);
            }
            catch (EntryPointNotFoundException) {
            }
            catch (DllNotFoundException) {
            }
            canTryUnix = false;
            return(null);
        }