예제 #1
0
 public static void Main(string[] args)
 {
     var stdin = new Pipe();
     stdin.Open(0);
     stdin.Read(Encoding.ASCII, (str) => {
         str = str.TrimEnd(new char[] { '\r', '\n' });
         if (str.StartsWith("fib ")) {
             int n;
             if (!int.TryParse(str.Substring("fib ".Length), out n)) {
                 Console.WriteLine("Supply an integer to the fib command");
                 return;
             }
             TimeSpan span = TimeSpan.Zero;
             BigInteger res = 0;
             Loop.Default.QueueUserWorkItem(() => {
                 var now = DateTime.Now;
                 res = Fibonacci(n);
                 span = DateTime.Now - now;
             }, () => {
                 Console.WriteLine("{0}: fib({1}) = {2}", span, n, res);
             });
         } else if (str == "quit") {
             stdin.Close();
         } else if (str == "help") {
             Console.WriteLine("Available commands: ");
             Console.WriteLine("fib <n:int> - start a thread which calculates fib");
             Console.WriteLine("help - displays help");
             Console.WriteLine("quit - quits the program");
         } else {
             Console.WriteLine("Unknown command");
         }
     });
     stdin.Resume();
     Loop.Default.Run();
 }
예제 #2
0
		public static async Task MainAsync()
		{
			var stdin = new Pipe();
			stdin.Open((IntPtr)0);
			string str = null;
			while ((str = await stdin.ReadStringAsync()) != null) {
				str = str.TrimEnd(new char[] { '\r', '\n' });
				if (str.StartsWith("fib ")) {
					int n;
					if (!int.TryParse(str.Substring("fib ".Length), out n)) {
						Console.WriteLine("Supply an integer to the fib command");
						return;
					}
					TimeSpan span = TimeSpan.Zero;
					BigInteger res = 0;
					Loop.Default.QueueUserWorkItem(() => {
						var now = DateTime.Now;
						res = Fibonacci(n);
						span = DateTime.Now - now;
					}, () => {
						Console.WriteLine("{0}: fib({1}) = {2}", span, n, res);
					});
				} else if (str == "quit") {
					break;
				} else if (str == "help") {
					Console.WriteLine("Available commands: ");
					Console.WriteLine("fib <n:int> - start a thread which calculates fib");
					Console.WriteLine("help - displays help");
					Console.WriteLine("quit - quits the program");
				} else {
					Console.WriteLine("Unknown command");
				}
			}
			stdin.Shutdown();
		}
예제 #3
0
		public static void Main(string[] args)
		{
			var stdin = new Pipe();
			stdin.Open((IntPtr)0);
			Loop.Default.Run(async delegate {
				await MainAsync();
			});
		}
예제 #4
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);
        }
예제 #5
0
		public static void Main(string[] args)
		{
			/*
			 * This works on unix only if .exe files are somehow associated
			 * with /usr/bin/mono. A good way to test it if they are is to
			 * set them to executables (chmod +x Test.exe) and then just
			 * try to run from command line: ./Test.exe
			 * If they execute, this example should work as well
			 */
			Loop.Default.Run(async () => {
				string file = Path.Combine(Directory.GetCurrentDirectory(), "Test.exe");
				using (var stdout = new Pipe() { Writeable = true })
				using (var process = Process.Spawn(new ProcessOptions() {
					File = file,
					Arguments = new string[] { file },
					Streams = new UVStream[] { null, stdout },
				})) {
					Console.WriteLine(await stdout.ReadStringAsync());
				}
			});
		}
예제 #6
0
		public static void Main(string[] args)
		{
			var stdin = new Pipe();
			stdin.Open((IntPtr)0);
			Loop.Default.Run(MainAsync);
		}