コード例 #1
0
ファイル: TcpClientSocket.cs プロジェクト: gigi81/sharpuv
 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
ファイル: Filesystem.cs プロジェクト: gigi81/sharpuv
 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
ファイル: Filesystem.cs プロジェクト: gigi81/sharpuv
        private void OnRemoveDirectory(IntPtr req)
        {
            var callback = _rmdirCallback;
            _rmdirCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnRemoveDirectory, this.DirectoryRemoved);
        }
コード例 #4
0
ファイル: Filesystem.cs プロジェクト: gigi81/sharpuv
        private void OnDelete(IntPtr req)
        {
            var callback = _deleteCallback;
            _deleteCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnDelete, this.Deleted);
        }
コード例 #5
0
ファイル: Filesystem.cs プロジェクト: gigi81/sharpuv
        private void OnCreateDirectory(IntPtr req)
        {
            var callback = _mkdirCallback;
            _mkdirCallback = null;

            callback.Invoke(this.FreeRequest(req), this.OnCreateDirectory, this.DirectoryCreated);
        }
コード例 #6
0
ファイル: Filesystem.cs プロジェクト: gigi81/sharpuv
        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
ファイル: TcpClientSocket.cs プロジェクト: gigi81/sharpuv
        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
ファイル: TcpClientSocket.cs プロジェクト: gigi81/sharpuv
        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
ファイル: Filesystem.cs プロジェクト: gigi81/sharpuv
        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
ファイル: Filesystem.cs プロジェクト: gigi81/sharpuv
        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;
            }
        }