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; } }
public void Copy(string source, string destination, Action<UvArgs> callback = null) { _copy = new FileCopy(source, destination, this.OnCopyInternal); _copyCallback = new UvCallback(this, callback); }
private void OnRemoveDirectory(IntPtr req) { var callback = _rmdirCallback; _rmdirCallback = null; callback.Invoke(this.FreeRequest(req), this.OnRemoveDirectory, this.DirectoryRemoved); }
private void OnDelete(IntPtr req) { var callback = _deleteCallback; _deleteCallback = null; callback.Invoke(this.FreeRequest(req), this.OnDelete, this.Deleted); }
private void OnCreateDirectory(IntPtr req) { var callback = _mkdirCallback; _mkdirCallback = null; callback.Invoke(this.FreeRequest(req), this.OnCreateDirectory, this.DirectoryCreated); }
private void OnCopyInternal(UvArgs args) { var callback = _copyCallback; _copyCallback = null; var copy = _copy; _copy = null; callback.Invoke(args.Code, this.OnCopy, this.Copied); }
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(); } }
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; } }
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); }
/// <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); }
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); } }
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); }
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); }
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); }
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; } }
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; } }
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; } }
/// <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; } }