Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        private void OnRemoveDirectory(IntPtr req)
        {
            var callback = _rmdirCallback;

            _rmdirCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnRemoveDirectory, this.DirectoryRemoved);
        }
Exemplo n.º 3
0
        private void OnCreateDirectory(IntPtr req)
        {
            var callback = _mkdirCallback;

            _mkdirCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnCreateDirectory, this.DirectoryCreated);
        }
Exemplo n.º 4
0
        private void OnDelete(IntPtr req)
        {
            var callback = _deleteCallback;

            _deleteCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnDelete, this.Deleted);
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 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;
     }
 }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 16
0
        /// <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;
            }
        }
Exemplo n.º 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);
 }