Example #1
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()));
            }
        }
Example #2
0
 protected void OnError(UVException exception)
 {
     if (Error != null)
     {
         Error(exception);
     }
 }
Example #3
0
        internal static Exception Map(uv_err_code error, string name = null)
        {
            if (error == uv_err_code.UV_OK)
            {
                return(null);
            }

            switch (error)
            {
            case uv_err_code.UV_EINVAL:
                return(new ArgumentException(UVException.StringError(error)));

            case uv_err_code.UV_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 uv_err_code.UV_EADDRINUSE:
                return(new SocketException(10048));

            case uv_err_code.UV_EADDRNOTAVAIL:
                return(new SocketException(10049));

            case uv_err_code.UV_ECONNREFUSED:
                return(new SocketException(10061));

            case uv_err_code.UV_ENOTSUP:
                return(new NotSupportedException());

            default:
                return(new UVException(error));
            }
        }
Example #4
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));
        }
Example #5
0
        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);
        }
Example #6
0
 protected void OnError(UVException exception)
 {
     if (Error != null) {
         Error(exception);
     }
 }