Dispatch messages in a loop, returning when the communication handle is closed. This function handles common error messages, passing other messages to the given function `f`.
(handle: &CommHandle,
mut f: F)
| 152 | /// other messages to the given function `f`. |
| 153 | /// |
| 154 | fn dispatch_loop<F>(handle: &CommHandle, |
| 155 | mut f: F) |
| 156 | where |
| 157 | F: FnMut(syscalls::Message) -> (), |
| 158 | { |
| 159 | loop { |
| 160 | match syscalls::receive(handle) { |
| 161 | Ok(syscalls::Message::Short( |
| 162 | message::CLOSE, _, _)) => { |
| 163 | // Close this file handler, dropping comm_handle |
| 164 | return; |
| 165 | }, |
| 166 | Err(syscalls::SYSCALL_ERROR_RECV_BLOCKING) => { |
| 167 | // Waiting for a message |
| 168 | // => Send an error message |
| 169 | if let Err((err, _msg)) = syscalls::send(handle, |
| 170 | syscalls::Message::Short( |
| 171 | message::ERROR, 0, 0)) { |
| 172 | // Failed to send. Not clear what to do here |
| 173 | println!("[std:dispatch_loop] Blocked recv: {}", err); |
| 174 | } |
| 175 | // Wait and try again |
| 176 | syscalls::thread_yield(); |
| 177 | }, |
| 178 | Err(syscalls::SYSCALL_ERROR_CLOSED) => { |
| 179 | // Other Rendezvous handles have been dropped |
| 180 | return; |
| 181 | }, |
| 182 | Ok(msg) => f(msg), |
| 183 | Err(code) => { |
| 184 | println!("[std:dispatch_loop] Receive error {}", code); |
| 185 | // Wait and try again |
| 186 | syscalls::thread_yield(); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /// Serve messages received from a communication channel |
| 193 | /// reading and writing data from a file |
no test coverage detected