MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / dispatch_loop

Function dispatch_loop

euralios_std/src/server.rs:154–190  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

152/// other messages to the given function `f`.
153///
154fn dispatch_loop<F>(handle: &CommHandle,
155 mut f: F)
156where
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

Callers 3

handle_file_readwriteFunction · 0.85
handle_file_readonlyFunction · 0.85
handle_directoryFunction · 0.85

Calls 3

receiveFunction · 0.85
sendFunction · 0.85
thread_yieldFunction · 0.85

Tested by

no test coverage detected