コード例 #1
1
ファイル: Tcp.cs プロジェクト: carlokok/LibuvSharp
        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);
        }
コード例 #2
0
ファイル: Pipe.cs プロジェクト: carlokok/LibuvSharp
        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);
        }