浏览代码

Did some stuff.

themultiplexer 8 年前
父节点
当前提交
7439c327ab
共有 1 个文件被更改,包括 21 次插入7 次删除
  1. 21
    7
      hw6/task1/src/main.rs

+ 21
- 7
hw6/task1/src/main.rs 查看文件

13
 
13
 
14
     let arguments: Vec<String> = args().collect();
14
     let arguments: Vec<String> = args().collect();
15
 
15
 
16
+    const BUFFER_SIZE : usize = 256;
17
+
16
     if arguments.len() > 2 {
18
     if arguments.len() > 2 {
17
 
19
 
18
         let (reader, writer) = pipe().unwrap();
20
         let (reader, writer) = pipe().unwrap();
19
-        let msg = "hello from parent";
21
+        let numbers = arguments[1..].to_vec();
22
+
20
         let pid = fork();
23
         let pid = fork();
21
         match pid {
24
         match pid {
22
             Ok(Child) => {
25
             Ok(Child) => {
23
-                let mut read_buf = [0u8; 32];
26
+                let mut read_buf = [0u8; BUFFER_SIZE];
24
                 let bytes_read = read(reader, &mut read_buf).unwrap();
27
                 let bytes_read = read(reader, &mut read_buf).unwrap();
25
-                let msg_received = str::from_utf8(&read_buf[0..bytes_read]).unwrap();
26
-                println!("{} received from parent:{:?}", getpid(), msg_received);
28
+                let msg_received = str::from_utf8(&read_buf[0 .. bytes_read]).unwrap();
29
+
30
+
31
+                match sum_strings(split_into_strings(msg_received)) {
32
+                    Ok(res) => {
33
+                        println!("{}", res)
34
+                    },
35
+                    Err(_) => {},
36
+                }
37
+
38
+                //let result = sum_strings(numbers);
39
+
27
             }
40
             }
28
 
41
 
29
             Ok(Parent { child }) => {
42
             Ok(Parent { child }) => {
43
+                for s in numbers {
44
+                    write(writer, concatenate_strings(s, " ").as_bytes());
45
+                }
30
 
46
 
31
-                println!("sending to child with pid:{}", child);
32
-                write(writer, msg.as_bytes()).unwrap();
33
 
47
 
34
                 if let Ok(ws) = wait() {
48
                 if let Ok(ws) = wait() {
35
                     if let WaitStatus::Exited(child_pid, exit_code) = ws {
49
                     if let WaitStatus::Exited(child_pid, exit_code) = ws {
85
         }
99
         }
86
     }
100
     }
87
     Ok(prod)
101
     Ok(prod)
88
-}
102
+}

正在加载...
取消
保存