Exemplo n.º 1
0
        public static IAsyncResult BeginLaunch(ProcessStartInfo info, AsyncCallback callback, LaunchOptions options = null)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
            socket.Listen(1000);
            IPEndPoint ep = (IPEndPoint)socket.LocalEndPoint;

            // We need to inject our arguments into the psi
            info.Arguments = string.Format("{0} --debug --debugger-agent=transport=dt_socket,address={1}:{2}{3} {4}",
                                           options == null || !options.Valgrind ? "" : info.FileName,
                                           ep.Address,
                                           ep.Port,
                                           options == null || options.AgentArgs == null ? "" : "," + options.AgentArgs,
                                           info.Arguments);

            if (options != null && options.Valgrind)
            {
                info.FileName = "valgrind";
            }

            Process p;

            if (options != null && options.CustomProcessLauncher != null)
            {
                p = options.CustomProcessLauncher(info);
            }
            else
            {
                p = Process.Start(info);
            }

            p.Exited += delegate(object sender, EventArgs eargs) {
                socket.Close();
            };

            LaunchCallback c = new LaunchCallback(LaunchInternal);

            return(c.BeginInvoke(p, socket, callback, socket));
        }
Exemplo n.º 2
0
 public static VirtualMachine Launch(ProcessStartInfo info, LaunchOptions options = null)
 {
     return(EndLaunch(BeginLaunch(info, null, options)));
 }