Exemplo n.º 1
0
        public void Spawn()
        {
            var options = new uv_process_options_t();

            options.exit_cb = static_exit;
            options.file    = this.File;
            var args = new IntPtr[Arguments.Count + 3];

            args[0] = Marshal.StringToHGlobalAuto(this.CurrentWorkingDirectory);
            args[1] = Marshal.StringToHGlobalAuto(this.File);
            args[args.Length - 1] = IntPtr.Zero;
            for (int i = 0; i < Arguments.Count; i++)
            {
                args[i + 2] = Marshal.StringToHGlobalAuto(Arguments[i]);
            }
            options.args = args;
            var env = new IntPtr[Environment.Count + 1];

            env[Environment.Count - 1] = IntPtr.Zero;
            for (int i = 0; i < Environment.Count; i++)
            {
                env[i] = Marshal.StringToHGlobalAuto(Environment[i]);
            }
            options.env           = env;
            options.stdout_stream = _stdout;
            options.stderr_stream = _stderr;
            Util.CheckError(uv_spawn(_handle, options));
            StdOut.ReadStart();
            StdErr.ReadStart();
        }
Exemplo n.º 2
0
        public void Listen(IPEndPoint endpoint)
        {
            var info = uv_ip4_addr(endpoint.Address.ToString(), endpoint.Port);

            Util.CheckError(uv_tcp_bind(this._handle, info));
            Util.CheckError(uv_listen(this._handle, 128, unmanaged_callback));
        }
Exemplo n.º 3
0
        public void Connect(IPEndPoint endpoint, Action OnConnect)
        {
            var info = uv_ip4_addr(endpoint.Address.ToString(), endpoint.Port);

            Util.CheckError(uv_tcp_connect(this.connection, this._handle, info, unmanaged_connect_cb));
            this.OnConnect += OnConnect;
        }
Exemplo n.º 4
0
        static void static_read(IntPtr stream, IntPtr nread, uv_buf_t buf)
        {
            int size = (int)nread;

            if (size < 0)
            {
                if ((int)buf.data != 0)
                {
                    Marshal.FreeHGlobal(buf.data);
                }
                IntPtr shutdown = Marshal.AllocHGlobal(Sizes.ShutdownT);
                Util.CheckError(uv_shutdown(shutdown, stream, after_shutdown));
                return;
            }
            if (size == 0)
            {
                Marshal.FreeHGlobal(buf.data);
                return;
            }
            byte[] data = new byte[size];
            Marshal.Copy(buf.data, data, 0, size);
            var handle            = (uv_handle_t)Marshal.PtrToStructure(stream, typeof(uv_handle_t));
            var instance_gchandle = GCHandle.FromIntPtr(handle.data);
            var stream_instance   = (UVStream)instance_gchandle.Target;

            stream_instance.HandleRead(data);
            Marshal.FreeHGlobal(buf.data);
        }
Exemplo n.º 5
0
        public static void StaticCallback(IntPtr server_ptr, int status)
        {
            Util.CheckError(status);
            var handle   = (uv_handle_t)Marshal.PtrToStructure(server_ptr, typeof(uv_handle_t));
            var instance = GCHandle.FromIntPtr(handle.data);
            var server   = (TcpServer)instance.Target;

            server.callback(new TcpSocket(server._handle));
        }
Exemplo n.º 6
0
        static void after_write(IntPtr write_req, int status)
        {
            Util.CheckError(status);
            var req = (uv_req_t)Marshal.PtrToStructure(write_req, typeof(uv_req_t));

            //var handle = GCHandle.FromIntPtr(req.data);
            //handle.Free();
            Marshal.FreeHGlobal(write_req);
        }
Exemplo n.º 7
0
        internal static void StaticCallback(IntPtr watcher, int status)
        {
            Util.CheckError(status);
            var handle           = (uv_handle_t)Marshal.PtrToStructure(watcher, typeof(uv_handle_t));
            var instance         = GCHandle.FromIntPtr(handle.data);
            var watcher_instance = (Watcher)instance.Target;

            watcher_instance.callback();
        }
Exemplo n.º 8
0
        public TcpServer(Action <TcpSocket> callback)
        {
            this.callback = callback;
            this._handle  = Marshal.AllocHGlobal(Sizes.TcpT);
            Util.CheckError(uv_tcp_init(this._handle));
            var handle = (uv_handle_t)Marshal.PtrToStructure(this._handle, typeof(uv_handle_t));

            this.me     = GCHandle.Alloc(this);
            handle.data = GCHandle.ToIntPtr(this.me);
            Marshal.StructureToPtr(handle, this._handle, true);
        }
Exemplo n.º 9
0
        static void after_shutdown(IntPtr shutdown, int status)
        {
            Util.CheckError(status);
            var tmp              = (uv_shutdown_t)Marshal.PtrToStructure(shutdown, typeof(uv_shutdown_t));
            var handle           = (uv_handle_t)Marshal.PtrToStructure(tmp.handle, typeof(uv_handle_t));
            var instance         = GCHandle.FromIntPtr(handle.data);
            var watcher_instance = (UVStream)instance.Target;

            watcher_instance.HandleClose();
            Marshal.FreeHGlobal(shutdown);
        }
Exemplo n.º 10
0
        public Watcher(Action callback, int size)
        {
            this.callback = callback;
            this._handle  = Marshal.AllocHGlobal(size);
            Util.CheckError(this.InitImpl());
            var handle = (uv_handle_t)Marshal.PtrToStructure(this._handle, typeof(uv_handle_t));

            this.me     = GCHandle.Alloc(this);
            handle.data = GCHandle.ToIntPtr(this.me);
            Marshal.StructureToPtr(handle, this._handle, true);
        }
Exemplo n.º 11
0
        static void unmanaged_connect_cb(IntPtr connection, int status)
        {
            Util.CheckError(status);
            var tmp             = (uv_connect_t)Marshal.PtrToStructure(connection, typeof(uv_connect_t));
            var handle          = (uv_handle_t)Marshal.PtrToStructure(tmp.handle, typeof(uv_handle_t));
            var instance        = GCHandle.FromIntPtr(handle.data);
            var socket_instance = (TcpSocket)instance.Target;

            socket_instance.Stream = new UVStream(socket_instance._handle);
            socket_instance.Stream.ReadStart();
            socket_instance.HandleConnect();
        }
Exemplo n.º 12
0
        public TcpSocket()
        {
            this._handle = Marshal.AllocHGlobal(Sizes.TcpT);
            Util.CheckError(uv_tcp_init(this._handle));
            var handle = (uv_handle_t)Marshal.PtrToStructure(this._handle, typeof(uv_handle_t));

            this.me     = GCHandle.Alloc(this);
            handle.data = GCHandle.ToIntPtr(this.me);
            Marshal.StructureToPtr(handle, this._handle, true);
            this.connection = Marshal.AllocHGlobal(Sizes.ConnectT);
            //can't attach anything to connect_t, it would get nulled
        }
Exemplo n.º 13
0
        public TcpSocket(IntPtr ServerHandle)
        {
            this._handle = Marshal.AllocHGlobal(Sizes.TcpT);
            Util.CheckError(uv_tcp_init(this._handle));
            Util.CheckError(uv_accept(ServerHandle, this._handle));
            var handle = (uv_handle_t)Marshal.PtrToStructure(this._handle, typeof(uv_handle_t));

            this.me     = GCHandle.Alloc(this);
            handle.data = GCHandle.ToIntPtr(this.me);
            Marshal.StructureToPtr(handle, this._handle, true);
            this.Stream = new UVStream(this._handle);
        }
Exemplo n.º 14
0
        public void Write(byte[] data, int length)
        {
            IntPtr write_request = Marshal.AllocHGlobal(Sizes.WriteT);
            var    dataptrhandle = GCHandle.Alloc(data, GCHandleType.Pinned);
            // This is not being freed, which needs to be fixed
            IntPtr dat = dataptrhandle.AddrOfPinnedObject();

            uv_buf_t[] buf = new uv_buf_t[1];
            buf[0].data = dat;
                        #if __MonoCS__
            buf[0].len = (IntPtr)length;
                        #else
            buf[0].len = (ulong)length;
                        #endif
            var req = (uv_req_t)Marshal.PtrToStructure(write_request, typeof(uv_req_t));
            req.data = dat;
            Marshal.StructureToPtr(req, write_request, true);
            Util.CheckError(uv_write(write_request, this.handle, buf, 1, after_write));
        }
Exemplo n.º 15
0
 public void Listen(string endpoint)
 {
     Util.CheckError(uv_pipe_bind(this._handle, endpoint));
     Util.CheckError(uv_listen(this._handle, 128, unmanaged_callback));
 }
Exemplo n.º 16
0
 public void Start()
 {
     Util.CheckError(this.StartImpl());
 }
Exemplo n.º 17
0
 public void Again()
 {
     Util.CheckError(uv_timer_again(this._handle));
 }
Exemplo n.º 18
0
 public void Connect(string path, Action OnConnect)
 {
     Util.CheckError(uv_pipe_connect(this.connection, this._handle, path, unmanaged_connect_cb));
     this.OnConnect += OnConnect;
 }
Exemplo n.º 19
0
 public void Stop()
 {
     Util.CheckError(this.StopImpl());
 }
Exemplo n.º 20
0
 // Instance Methods
 public void ReadStart()
 {
     Util.CheckError(uv_read_start(this.handle, static_alloc, static_read));
 }
Exemplo n.º 21
0
 public void ReadStop()
 {
     Util.CheckError(uv_read_stop(this.handle));
 }