예제 #1
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;
     }
 }
예제 #2
0
 public void Copy(string source, string destination, Action<UvArgs> callback = null)
 {
     _copy = new FileCopy(source, destination, this.OnCopyInternal);
     _copyCallback = new UvCallback(this, callback);
 }
예제 #3
0
        private void OnRemoveDirectory(IntPtr req)
        {
            var callback = _rmdirCallback;
            _rmdirCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnRemoveDirectory, this.DirectoryRemoved);
        }
예제 #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 OnCreateDirectory(IntPtr req)
        {
            var callback = _mkdirCallback;
            _mkdirCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnCreateDirectory, this.DirectoryCreated);
        }
예제 #6
0
        private void OnCopyInternal(UvArgs args)
        {
            var callback = _copyCallback;
            _copyCallback = null;
            var copy = _copy;
            _copy = null;

            callback.Invoke(args.Code, this.OnCopy, this.Copied);
        }
예제 #7
0
파일: UvStream.cs 프로젝트: gigi81/sharpuv
        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();
            }
        }
예제 #8
0
파일: File.cs 프로젝트: gigi81/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;
            }
        }
예제 #9
0
파일: UvHandle.cs 프로젝트: gigi81/sharpuv
        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
파일: UvHandle.cs 프로젝트: gigi81/sharpuv
        /// <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);
        }
예제 #11
0
        public void Resolve(string node, string service, Action<UvArgs<IPEndPoint[]>> callback = null)
        {
            var hints = addrinfo.CreateHints();
            var hintsPtr = this.Loop.Allocs.Alloc(Marshal.SizeOf(typeof(addrinfo)));
            Marshal.StructureToPtr(hints, hintsPtr, fDeleteOld: false);

            try
            {
                _resolveReq = this.Loop.Requests.Create(uv_req_type.UV_GETADDRINFO);
                CheckError(Uvi.uv_getaddrinfo(this.Loop.Handle, _resolveReq, _resolveDelegate, node, service, hintsPtr));
                this.Status = HandleStatus.Resolving;
                _resolveCallback = new UvEndPointsCallback(this, callback);
            }
            catch (Exception)
            {
                this.Loop.Requests.Delete(_resolveReq);
                _connectCallback = null;
                throw;
            }
            finally
            {
                this.Loop.Allocs.Free(hintsPtr);
            }
        }
예제 #12
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);
        }
예제 #13
0
파일: File.cs 프로젝트: gigi81/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);
        }
예제 #14
0
파일: File.cs 프로젝트: gigi81/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);
        }
예제 #15
0
        public void CreateDirectory(string path, FilePermissions permissions, Action<UvArgs> callback = null)
        {
            IntPtr req = IntPtr.Zero;

            try
            {
                req = this.CreateRequest();
                CheckError(Uvi.uv_fs_mkdir(this.Loop.Handle, req, path, (int)permissions, _mkdirDelegate));
                _mkdirCallback = new UvCallback(this, callback);
            }
            catch (Exception)
            {
                this.FreeRequest(req);
                throw;
            }
        }
예제 #16
0
파일: UvStream.cs 프로젝트: gigi81/sharpuv
        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;
            }
        }
예제 #17
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;
            }
        }
예제 #18
0
파일: File.cs 프로젝트: gigi81/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;
            }
        }