public static void Connect(Loop loop, IPAddress ipAddress, int port, Action<Exception, Tcp> callback) { Ensure.ArgumentNotNull(loop, "loop"); Ensure.ArgumentNotNull(ipAddress, "ipAddress"); Ensure.ArgumentNotNull(callback, "callback"); ConnectRequest cpr = new ConnectRequest(); Tcp socket = new Tcp(loop); cpr.Callback = (status, cpr2) => { if (status == 0) { callback(null, socket); } else { socket.Close(); callback(Ensure.Success(loop), null); } }; int r; if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { r = uv_tcp_connect(cpr.Handle, socket.handle, UV.uv_ip4_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd); } else { r = uv_tcp_connect6(cpr.Handle, socket.handle, UV.uv_ip6_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd); } Ensure.Success(r, loop); }
public static void Chown(Loop loop, string path, int uid, int gid, Action<Exception> callback) { var fsr = new FileSystemRequest(); fsr.Callback = (ex, fsr2) => { callback(ex); }; int r = uv_fs_chown(loop.Handle, fsr.Handle, path, uid, gid, FileSystemRequest.StaticEnd); Ensure.Success(r, loop); }
public TTY(Loop loop, int fd, bool readable) : base(loop, HandleType.UV_TTY) { FileDescriptor = fd; int r = uv_tty_init(loop.NativeHandle, NativeHandle, fd, (readable ? 1 : 0)); Ensure.Success(r, Loop); }
public static void Create(Loop loop, string path, int mode, Action<Exception> callback) { var fsr = new FileSystemRequest(); fsr.Callback = callback; int r = uv_fs_mkdir(loop.NativeHandle, fsr.Handle, path, mode, FileSystemRequest.CallbackDelegate); Ensure.Success(r); }
public static UVTimer Every(Loop loop, TimeSpan repeat, Action callback) { var timer = new UVTimer(loop); timer.Tick += callback; timer.Start(repeat, repeat); return timer; }
public TTY(Loop loop, IntPtr fd, bool readable) : base(loop, UvHandleType.UV_TTY) { FileDescriptor = fd; int r = uv_tty_init(loop.Handle, handle, fd, (readable ? 1 : 0)); Ensure.Success(r, Loop); }
public void Close(Loop loop, Action<Exception> callback) { var fsr = new FileSystemRequest(); fsr.Callback = callback; int r = uv_fs_close(loop.NativeHandle, fsr.Handle, FileDescriptor, FileSystemRequest.CallbackDelegate); Ensure.Success(r); }
internal UVStream(Loop loop, IntPtr handle) : base(loop, handle) { read_cb_unix = read_callback_u; read_cb_win = read_callback_w; stream = (uv_stream_t *)(handle.ToInt64() + Handle.Size(HandleType.UV_HANDLE)); }
public static void Delete(Loop loop, string path, Action<Exception> callback) { var fsr = new FileSystemRequest(); fsr.Callback = callback; int r = uv_fs_rmdir(loop.NativeHandle, fsr.Handle, path, FileSystemRequest.StaticEnd); Ensure.Success(r, loop); }
public static void Chown(Loop loop, string path, int uid, int gid, Action<Exception> callback) { var fsr = new FileSystemRequest(); fsr.Callback = callback; int r = uv_fs_chown(loop.NativeHandle, fsr.Handle, path, uid, gid, FileSystemRequest.CallbackDelegate); Ensure.Success(r); }
public FileSystemWatcher(Loop loop, string path, FileSystemEventFlags flags) : base(loop, HandleType.UV_FS_EVENT) { uv_fs_event = fs_event; int r = uv_fs_event_init(loop.NativeHandle, NativeHandle, path, uv_fs_event, (int)flags); Ensure.Success(r, loop); }
public static void Rename(Loop loop, string path, string newPath, Action<Exception> callback) { var fsr = new FileSystemRequest(); fsr.Callback = callback; int r = uv_fs_rename(loop.NativeHandle, fsr.Handle, path, newPath, fsr.End); Ensure.Success(r); }
public FileSystemEvent(Loop loop, string path) : base(loop, UvHandleType.UV_FS_EVENT) { uv_fs_event = fs_event; int r = uv_fs_event_init(loop.Handle, handle, path, uv_fs_event, 0); Ensure.Success(r, loop); }
public SignalWatcher(Loop loop, Signum signum, Action callback) : this(loop, new Signum[] { signum }, (num) => { if (callback != null) { callback(); } }) { }
public Poll(Loop loop, int fd) : base(loop, UvHandleType.UV_POLL) { int r = uv_poll_init(loop.Handle, handle, fd); Ensure.Success(r, Loop); poll_cb += pollcallback; }
internal static void Success(int errorCode, Loop loop) { if (errorCode < 0) { var ex = Success(loop); if (ex != null) { throw ex; } } }
internal Handle(Loop loop, IntPtr handle) { Ensure.ArgumentNotNull(loop, "loop"); this.handle = handle; GCHandle = GCHandle.Alloc(this); Loop = loop; Loop.handles[handle] = this; }
public static void Delete(Loop loop, string path, Action<Exception> callback) { var fsr = new FileSystemRequest(); fsr.Callback = (ex, fsr2) => { if (callback != null) { callback(ex); }; }; int r = uv_fs_rmdir(loop.Handle, fsr.Handle, path, FileSystemRequest.StaticEnd); Ensure.Success(r, loop); }
public Udp(Loop loop) : base(loop, HandleType.UV_UDP) { int r = uv_udp_init(loop.NativeHandle, NativeHandle); Ensure.Success(r, loop); // we can't supply just recv_start_callback in Receive // because it will create a temporary delegate which could(and will) be garbage collected at any time // happens in my case after 10 or 20 calls // so we have to reference it, so it won't garbage collect it until the object itself // is gone recv_start_cb_win = recv_start_callback_w; recv_start_cb_unix = recv_start_callback_u; }
public static void Open(Loop loop, string path, UVFileAccess access, Action<Exception, UVFile> callback) { var fsr = new FileSystemRequest(path); fsr.Callback = (ex) => { UVFile file = null; if (fsr.Result != IntPtr.Zero) { file = new UVFile(loop, fsr.Result.ToInt32()); } Ensure.Success(ex, callback, file); }; int r = uv_fs_open(loop.NativeHandle, fsr.Handle, path, (int)access, 0, FileSystemRequest.CallbackDelegate); Ensure.Success(r); }
public void Read(Loop loop, int offset, ArraySegment<byte> segment, Action<Exception, int> callback) { var datagchandle = GCHandle.Alloc(segment.Array, GCHandleType.Pinned); var fsr = new FileSystemRequest(); fsr.Callback = (ex) => { Ensure.Success(ex, callback, fsr.Result.ToInt32()); datagchandle.Free(); }; UnixBufferStruct[] buf = new UnixBufferStruct[1]; buf[0] = new UnixBufferStruct(datagchandle.AddrOfPinnedObject() + segment.Offset, segment.Count); int r = uv_fs_read(loop.NativeHandle, fsr.Handle, FileDescriptor, buf, 1, offset, FileSystemRequest.CallbackDelegate); Ensure.Success(r); }
public static void Init(Loop loop) { Debug.Log("Application Init"); Window.Init(); Running = true; Curses.Raw = true; Curses.Echo = false; Curses.start_color(); Curses.use_default_colors(); Window.Standard.Keypad = true; Loop = loop; }
public static unsafe void Read(Loop loop, string path, Action<Exception, string[]> callback) { var fsr = new FileSystemRequest(); fsr.Callback = (ex) => { if (ex != null) { callback(ex, null); return; } int length = (int)fsr.Result; string[] res = new string[length]; sbyte *ptr = (sbyte *)fsr.Pointer; for (int i = 0; i < length; i++) { res[i] = new string(ptr); ptr += res[i].Length + 1; } callback(ex, res); }; uv_fs_readdir(loop.NativeHandle, fsr.Handle, path, 0, FileSystemRequest.StaticEnd); }
public static void Connect(Loop loop, string name, bool interProcessCommunication, Action<Exception, Pipe> callback) { Ensure.ArgumentNotNull(loop, "loop"); Ensure.ArgumentNotNull(name, "name"); Ensure.ArgumentNotNull(callback, "callback"); ConnectRequest cpr = new ConnectRequest(); Pipe pipe = new Pipe(loop, interProcessCommunication); cpr.Callback = (status, cpr2) => { if (status == 0) { callback(null, pipe); } else { pipe.Close(); callback(Ensure.Success(loop, name), null); } }; uv_pipe_connect(cpr.Handle, pipe.handle, name, ConnectRequest.StaticEnd); }
public AsyncCoreConnection(Loop loop, CoreConnection coreConnection) { Loop = loop; CoreConnection = coreConnection; listnotifier = new AsyncWatcher<QVariant>((packet) => OnReceivePacket(packet)); exceptionnotifier = new AsyncWatcher<Exception>((exception) => OnException(exception)); thread = new Thread((obj) => { coreConnection.ReceivePacket += (packet) => { listnotifier.Send(packet); }; coreConnection.Exception += (exception) => { //exceptionnotifier.Send(exception); }; coreConnection.Connect(); coreConnection.Loop(); }); }
public SignalWatcher(Loop loop, Signum[] signals, Action<Signum> callback) { Signals = signals; unixSignals = new UnixSignal[signals.Length]; for (int i = 0; i < signals.Length; i++) { unixSignals[i] = new UnixSignal((Mono.Unix.Native.Signum)signals[i]); } watcher = new AsyncWatcher<Signum>(loop); watcher.Callback += (key) => { if (callback != null) { callback(key); } }; thread = new Thread((o) => { while (true) { var index = UnixSignal.WaitAny(unixSignals); watcher.Send(Signals[index]); } }); }
public TTY(Loop loop, int fd) : this(loop, fd, true) { }
public static void Delete(Loop loop, string path) { Delete(loop, path, null); }
public static void Create(Loop loop, string path) { Create(loop, path, 511); }
public static void Create(Loop loop, string path, Action<Exception> callback) { Create(loop, path, 511, callback); }