Exemplo n.º 1
0
        private static void GetFileLength(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string path = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null;

            arguments.SetReturnValue(FileAuxiliary.GetFileLength64(path));
        }
Exemplo n.º 2
0
        private unsafe void OpenFileViewAccessor(string path, Action <IntPtr, long, Action> callback)
        {
            if (callback == null || !File.Exists(path))
            {
                response.StatusCode = 404;
                return;
            }
            MemoryMappedFile         mmf  = null;
            MemoryMappedViewAccessor mmva = null;
            Action closeMmf = () =>
            {
                if (mmva != null)
                {
                    mmva.Dispose();
                    mmva = null;
                }
                if (mmf != null)
                {
                    mmf.Dispose();
                    mmf = null;
                }
            };
            bool immediate_shutdown = false;

            try
            {
                mmf = MemoryMappedFile.CreateFromFile(path, FileMode.Open);
                long totalcount = FileAuxiliary.GetFileLength64(path);
                mmva = mmf.CreateViewAccessor(0, totalcount, MemoryMappedFileAccess.ReadWrite);
                SafeHandle handle = mmva.SafeMemoryMappedViewHandle;
                if (handle.IsInvalid)
                {
                    immediate_shutdown  = true;
                    response.StatusCode = 503;
                }
                else
                {
                    callback(handle.DangerousGetHandle(), totalcount, closeMmf);
                }
            }
            catch (Exception)
            {
                immediate_shutdown  = true;
                response.StatusCode = 500;
            }
            if (immediate_shutdown)
            {
                closeMmf();
            }
        }