Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 53
aipc, an async ipc library for aero#60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| [workspace] | ||
| members = ["apps/*", "servers/*"] | ||
| members = ["apps/*", "servers/*", "libs/*"] | ||
| [profile.release] | ||
| debug = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "aipc_test" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| authors = ["pitust <piotr@stelmaszek.com>"] | ||
| [dependencies] | ||
| std = { path = "../../libs/aero_std" } | ||
| aero_syscall = { path = "../../../src/aero_syscall" } | ||
| aipc = { path = "../../libs/aipc" } | ||
| postcard = { version = "0.7.3", features = ["alloc"] } | ||
| spin = "0.9" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Copyright (C) 2021-2022 The Aero Project Developers. | ||
| * | ||
| * This file is part of The Aero Project. | ||
| * | ||
| * Aero is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * Aero is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with Aero. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| use core::sync::atomic::{AtomicUsize, Ordering, AtomicBool}; | ||
| use aero_syscall::{sys_fork, sys_exit}; | ||
| use aipc::async_runtime::Listener; | ||
| #[aipc::def("TestObj")] | ||
| trait TestObj { | ||
| async fn create() -> TestObj; | ||
| async fn foo(&self); | ||
| async fn kill(&self); | ||
| } | ||
| #[aipc::def("ServerControlObj")] | ||
| trait ServerControlObj { | ||
| async fn create() -> ServerControlObj; | ||
| async fn can_control(&self) -> bool; | ||
| async fn quit(&self); | ||
| } | ||
| static COUNTER: AtomicUsize = AtomicUsize::new(1); | ||
| struct NoData { | ||
| data: usize, | ||
| } | ||
| #[aipc::object(TestObjSrv as TestObj)] | ||
| impl NoData { | ||
| fn create() -> NoData { | ||
| return NoData { | ||
| data: COUNTER.fetch_add(1, Ordering::SeqCst), | ||
| }; | ||
| } | ||
| fn foo(&self) { | ||
| println!("Hello from obj {}!", self.data); | ||
| } | ||
| } | ||
| static SCS_PERMIT_ONCE: AtomicBool = AtomicBool::new(true); | ||
| pub struct ServerControlState { | ||
| permitted: bool | ||
| } | ||
| #[aipc::object(ServerControlSrv as ServerControlObj)] | ||
| impl ServerControlState { | ||
| pub fn create() -> ServerControlState { | ||
| return ServerControlState { | ||
| permitted: SCS_PERMIT_ONCE.swap(false, Ordering::SeqCst) | ||
| }; | ||
| } | ||
| pub fn can_control(&self) -> bool { | ||
| self.permitted | ||
| } | ||
| pub fn quit(&self) { | ||
| if self.permitted { | ||
| println!("[ServerControlSrv] exiting!"); | ||
| aipc::async_runtime::spawn(async { | ||
| sys_exit(0); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| fn main() { | ||
| let mut rt = aipc::async_runtime::AsyncRuntime::new(); | ||
| rt.spawn(async { | ||
| let pid = sys_fork().unwrap(); | ||
| if pid == 0 { | ||
| // server | ||
| ServerControlSrv::listen(); | ||
| TestObjSrv::listen(); | ||
| } else { | ||
| // client | ||
| let ctl = ServerControlObj::create(pid).await; | ||
| let o = TestObj::create(pid).await; | ||
| o.foo().await; | ||
| ctl.quit().await; | ||
| sys_exit(0); | ||
| } | ||
| }); | ||
| rt.run(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of constructing a runtime manually at the start of the main function, it would be a much cleaner idea to initialize it lazily in the spawn function instead. So it will look like
apic::spawn(async {}). In future we; after we get the rust userland port sorted out we can switch to usingtokioas our async runtime.