Add try_get_list_result to PollEvents
This commit is contained in:
parent
baa5c4d4bf
commit
ebdfa5fa51
68
src/lib.rs
68
src/lib.rs
@ -1,8 +1,14 @@
|
||||
use std::{
|
||||
borrow::Cow, boxed::Box, os::mikros::{ipc::{
|
||||
self,
|
||||
rpc::{self, CallId, IncomingCall}
|
||||
}, Errno}, vec::Vec
|
||||
borrow::Cow,
|
||||
boxed::Box,
|
||||
os::mikros::{
|
||||
ipc::{
|
||||
self,
|
||||
rpc::{self, CallId, IncomingCall},
|
||||
},
|
||||
Errno,
|
||||
},
|
||||
vec::Vec,
|
||||
};
|
||||
|
||||
use bitflags::bitflags;
|
||||
@ -77,7 +83,7 @@ impl PendingPoll {
|
||||
}
|
||||
|
||||
pub fn try_get_result(&self) -> Option<PollEvents> {
|
||||
let res: PollEvents = postcard::from_bytes(&*self.call_id.try_get_return()?).unwrap();
|
||||
let res: PollEvents = postcard::from_bytes(&self.call_id.try_get_return()?).unwrap();
|
||||
Some(res)
|
||||
}
|
||||
|
||||
@ -112,6 +118,37 @@ impl PendingPoll {
|
||||
ipc::process_messages();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_get_list_result(polls: &[Self]) -> Option<Vec<PollEvents>> {
|
||||
let mut result_vec = Vec::with_capacity(polls.len());
|
||||
let mut poll_returned = false;
|
||||
let mut first_returned = 0;
|
||||
for (i, poll) in polls.iter().enumerate() {
|
||||
if let Some(poll_result) = poll.try_get_result() {
|
||||
result_vec.push(poll_result);
|
||||
if !poll_returned {
|
||||
first_returned = i;
|
||||
}
|
||||
poll_returned = true;
|
||||
} else if poll_returned {
|
||||
poll.cancel();
|
||||
if let Some(poll_result) = poll.try_get_result() {
|
||||
result_vec.push(poll_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
if poll_returned {
|
||||
for poll in &polls[0..first_returned] {
|
||||
poll.cancel();
|
||||
if let Some(poll_result) = poll.try_get_result() {
|
||||
result_vec.push(poll_result);
|
||||
}
|
||||
}
|
||||
Some(result_vec)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Client {
|
||||
@ -121,26 +158,16 @@ impl Client {
|
||||
|
||||
pub fn read(self, fd: u64, len: usize) -> Result<Vec<u8>, Errno> {
|
||||
postcard::from_bytes(
|
||||
&rpc::send_call(
|
||||
self.0,
|
||||
PROTO,
|
||||
0,
|
||||
&postcard::to_stdvec(&(fd, len)).unwrap(),
|
||||
)
|
||||
.get_return(),
|
||||
&rpc::send_call(self.0, PROTO, 0, &postcard::to_stdvec(&(fd, len)).unwrap())
|
||||
.get_return(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn write(self, fd: u64, data: &[u8]) -> Result<(), Errno> {
|
||||
postcard::from_bytes(
|
||||
&rpc::send_call(
|
||||
self.0,
|
||||
PROTO,
|
||||
1,
|
||||
&postcard::to_stdvec(&(fd, data)).unwrap(),
|
||||
)
|
||||
.get_return(),
|
||||
&rpc::send_call(self.0, PROTO, 1, &postcard::to_stdvec(&(fd, data)).unwrap())
|
||||
.get_return(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
@ -187,7 +214,8 @@ impl Client {
|
||||
|
||||
pub fn seek(&self, fd: u64, pos: SeekFrom) -> Result<u64, Errno> {
|
||||
postcard::from_bytes(
|
||||
&rpc::send_call(self.0, PROTO, 8, &postcard::to_stdvec(&(fd, pos)).unwrap()).get_return(),
|
||||
&rpc::send_call(self.0, PROTO, 8, &postcard::to_stdvec(&(fd, pos)).unwrap())
|
||||
.get_return(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user