Exemple #1
0
        internal static Exception Map(int systemErrorCode, string name = null)
        {
            // no error, just return null
            if (!(systemErrorCode < 0))
            {
                return(null);
            }

            // map some error codes
            var errorCode = UVException.Map(systemErrorCode);

            switch (errorCode)
            {
            case UVErrorCode.EINVAL:
                return(new ArgumentException(UVException.StringError(systemErrorCode)));

            case UVErrorCode.ENOENT:
                var path = (name == null ? System.IO.Directory.GetCurrentDirectory() : Path.Combine(System.IO.Directory.GetCurrentDirectory(), name));
                return(new System.IO.FileNotFoundException(string.Format("Could not find file '{0}'.", path), path));

            case UVErrorCode.ENOTSUP:
                return(new NotSupportedException());

            default:
                break;
            }

            // everything else is a UVException
            return(new UVException(systemErrorCode));
        }
Exemple #2
0
        void rcallback(IntPtr streamPointer, IntPtr size)
        {
            long nread = size.ToInt64();

            if (nread == 0)
            {
                return;
            }
            else if (nread < 0)
            {
                if (UVException.Map((int)nread) == UVErrorCode.EOF)
                {
                    Close(Complete);
                }
                else
                {
                    OnError(Ensure.Map((int)nread));
                    Close();
                }
            }
            else
            {
                OnData(ByteBufferAllocator.Retrieve(size.ToInt32()));
            }
        }
        public static void Read(Loop loop, string path, Action <Exception, UVDirectoryEntity[]> callback)
        {
            var fsr = new FileSystemRequest();

            fsr.Callback = (ex) =>
            {
                if (ex != null)
                {
                    callback(ex, null);
                    return;
                }

                var         list = new List <UVDirectoryEntity>();
                uv_dirent_t entity;
                while (UVException.Map(uv_fs_scandir_next(fsr.Handle, out entity)) != UVErrorCode.EOF)
                {
                    list.Add(new UVDirectoryEntity(entity));
                }

                Ensure.Success(ex, callback, list.ToArray());
            };
            int r = uv_fs_scandir(loop.NativeHandle, fsr.Handle, path, 0, FileSystemRequest.CallbackDelegate);

            Ensure.Success(r);
        }