示例#1
0
文件: File.cs 项目: PlumpMath/sharpuv
        public void Open(string path, FileAccessMode access, FileOpenMode mode, FilePermissions permissions, Action <UvArgs> callback = null)
        {
            if (this.IsDisposed)
            {
                throw new InvalidOperationException("Cannot open a stream after it has been disposed");
            }

            if (this.Status != FileStatus.Closed)
            {
                throw new InvalidOperationException(String.Format("Cannot open a file handle when it's status is {0}", this.Status));
            }

            IntPtr req = IntPtr.Zero;

            try
            {
                req = this.CreateRequest();
                CheckError(uv_fs_open(this.Loop, req, path, access, mode, permissions, _openDelegate));
                this.Status   = FileStatus.Opening;
                _openCallback = new UvCallback(this, callback);
            }
            catch (Exception)
            {
                this.FreeRequest(req);
                throw;
            }
        }
示例#2
0
        private void OnRemoveDirectory(IntPtr req)
        {
            var callback = _rmdirCallback;

            _rmdirCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnRemoveDirectory, this.DirectoryRemoved);
        }
示例#3
0
        private void OnCreateDirectory(IntPtr req)
        {
            var callback = _mkdirCallback;

            _mkdirCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnCreateDirectory, this.DirectoryCreated);
        }
示例#4
0
        private void OnDelete(IntPtr req)
        {
            var callback = _deleteCallback;

            _deleteCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnDelete, this.Deleted);
        }
示例#5
0
        private void OnConnect(IntPtr connection, int status)
        {
            var callback = _connectCallback;

            _connectCallback = null;

            this.Status = status == 0 ? HandleStatus.Open : HandleStatus.Closed;
            callback.Invoke(status, this.OnConnect, this.Connected);
        }
示例#6
0
文件: File.cs 项目: PlumpMath/sharpuv
        private void OnOpen(IntPtr req)
        {
            var callback = _openCallback;

            _openCallback = null;

            _file       = this.FreeRequest(req);
            this.Status = _file != -1 ? FileStatus.Open : FileStatus.Closed;
            callback.Invoke(_file, this.OnOpen, this.Opened);
        }
示例#7
0
        private void OnCopyInternal(UvArgs args)
        {
            var callback = _copyCallback;

            _copyCallback = null;
            var copy = _copy;

            _copy = null;

            callback.Invoke(args.Code, this.OnCopy, this.Copied);
        }
示例#8
0
        /// <summary>
        /// Closes the stream
        /// </summary>
        public void Close(bool dispose = false, Action <UvArgs> callback = null)
        {
            if (this.Status != HandleStatus.Open)
            {
                return;
            }

            _disposeAfterClose = dispose;
            Uvi.uv_close(this.Handle, _closeDelegate);
            this.Status    = HandleStatus.Closing;
            _closeCallback = new UvCallback(this, callback);
        }
示例#9
0
        private void OnClose(IntPtr handle)
        {
            var callback = _closeCallback;

            _closeCallback = null;

            this.Status = HandleStatus.Closed;
            callback.Invoke((int)handle, this.OnClose, this.Closed);
            if (_disposeAfterClose)
            {
                this.Dispose(true);
            }
        }
示例#10
0
文件: File.cs 项目: PlumpMath/sharpuv
        private void OnClose(IntPtr req)
        {
            var callback = _closeCallback;

            _closeCallback = null;

            _file = this.FreeRequest(req);
            if (_file != -1)
            {
                this.Status = FileStatus.Closed;
            }

            this.Dispose(false);
            callback.Invoke(_file, this.OnClose, this.Closed);
        }
示例#11
0
 public void Connect(IntPtr address, Action <UvArgs> callback = null)
 {
     try
     {
         _address = address;
         CheckError(Uvi.uv_tcp_connect(this.Connection, this.Handle, _address, _connectDelegate));
         this.Status      = HandleStatus.Opening;
         _connectCallback = new UvCallback(this, callback);
     }
     catch (Exception)
     {
         _address         = this.Loop.Allocs.Free(_address);
         _connectCallback = null;
         throw;
     }
 }
示例#12
0
        public void RemoveDirectory(string path, Action <UvArgs> callback = null)
        {
            IntPtr req = IntPtr.Zero;

            try
            {
                req = this.CreateRequest();
                CheckError(Uvi.uv_fs_rmdir(this.Loop.Handle, req, path, _rmdirDelegate));
                _rmdirCallback = new UvCallback(this, callback);
            }
            catch (Exception)
            {
                this.FreeRequest(req);
                throw;
            }
        }
示例#13
0
        public void Delete(string path, Action <UvArgs> callback = null)
        {
            IntPtr req = IntPtr.Zero;

            try
            {
                req = this.CreateRequest();
                CheckError(Uvi.uv_fs_unlink(this.Loop.Handle, req, path, _deleteDelegate));
                _deleteCallback = new UvCallback(this, callback);
            }
            catch (Exception)
            {
                this.FreeRequest(req);
                throw;
            }
        }
示例#14
0
        private void OnShutdown(IntPtr req, int status)
        {
            var callback = _shutdownCallback;

            _shutdownCallback = null;

            this.Loop.Requests.Delete(req);

            try
            {
                callback.Invoke(status, this.OnShutdown, this.ShuttedDown);
            }
            finally
            {
                this.Close();
            }
        }
示例#15
0
        public void Shutdown(Action <UvArgs> callback = null)
        {
            IntPtr req = IntPtr.Zero;

            try
            {
                if (_isReading)
                {
                    this.ReadStop();
                }

                req = this.Loop.Requests.Create(uv_req_type.UV_SHUTDOWN);
                CheckError(Uvi.uv_shutdown(req, this.Handle, _shutdownDelegate));
                _shutdownCallback = new UvCallback(this, callback);
            }
            catch (Exception)
            {
                this.Loop.Requests.Delete(req);
                throw;
            }
        }
示例#16
0
文件: File.cs 项目: PlumpMath/sharpuv
        /// <summary>
        /// Closes the stream. After this call the stream will not be valid
        /// </summary>
        public void Close(Action <UvArgs> callback = null)
        {
            if (this.Status != FileStatus.Open)
            {
                throw new InvalidOperationException(String.Format("Cannot close the file handle while the status is {0}", this.Status));
            }

            IntPtr req = IntPtr.Zero;

            try
            {
                req = this.CreateRequest();
                CheckError(Uvi.uv_fs_close(this.Loop.Handle, req, _file, _closeDelegate));
                this.Status    = FileStatus.Closing;
                _closeCallback = new UvCallback(this, callback);
            }
            catch (Exception)
            {
                this.FreeRequest(req);
                throw;
            }
        }
示例#17
0
 public void Copy(string source, string destination, Action <UvArgs> callback = null)
 {
     _copy         = new FileCopy(source, destination, this.OnCopyInternal);
     _copyCallback = new UvCallback(this, callback);
 }