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::{
|
use std::{
|
||||||
borrow::Cow, boxed::Box, os::mikros::{ipc::{
|
borrow::Cow,
|
||||||
self,
|
boxed::Box,
|
||||||
rpc::{self, CallId, IncomingCall}
|
os::mikros::{
|
||||||
}, Errno}, vec::Vec
|
ipc::{
|
||||||
|
self,
|
||||||
|
rpc::{self, CallId, IncomingCall},
|
||||||
|
},
|
||||||
|
Errno,
|
||||||
|
},
|
||||||
|
vec::Vec,
|
||||||
};
|
};
|
||||||
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
@ -77,7 +83,7 @@ impl PendingPoll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_get_result(&self) -> Option<PollEvents> {
|
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)
|
Some(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,6 +118,37 @@ impl PendingPoll {
|
|||||||
ipc::process_messages();
|
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 {
|
impl Client {
|
||||||
@ -121,26 +158,16 @@ impl Client {
|
|||||||
|
|
||||||
pub fn read(self, fd: u64, len: usize) -> Result<Vec<u8>, Errno> {
|
pub fn read(self, fd: u64, len: usize) -> Result<Vec<u8>, Errno> {
|
||||||
postcard::from_bytes(
|
postcard::from_bytes(
|
||||||
&rpc::send_call(
|
&rpc::send_call(self.0, PROTO, 0, &postcard::to_stdvec(&(fd, len)).unwrap())
|
||||||
self.0,
|
.get_return(),
|
||||||
PROTO,
|
|
||||||
0,
|
|
||||||
&postcard::to_stdvec(&(fd, len)).unwrap(),
|
|
||||||
)
|
|
||||||
.get_return(),
|
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(self, fd: u64, data: &[u8]) -> Result<(), Errno> {
|
pub fn write(self, fd: u64, data: &[u8]) -> Result<(), Errno> {
|
||||||
postcard::from_bytes(
|
postcard::from_bytes(
|
||||||
&rpc::send_call(
|
&rpc::send_call(self.0, PROTO, 1, &postcard::to_stdvec(&(fd, data)).unwrap())
|
||||||
self.0,
|
.get_return(),
|
||||||
PROTO,
|
|
||||||
1,
|
|
||||||
&postcard::to_stdvec(&(fd, data)).unwrap(),
|
|
||||||
)
|
|
||||||
.get_return(),
|
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
@ -187,7 +214,8 @@ impl Client {
|
|||||||
|
|
||||||
pub fn seek(&self, fd: u64, pos: SeekFrom) -> Result<u64, Errno> {
|
pub fn seek(&self, fd: u64, pos: SeekFrom) -> Result<u64, Errno> {
|
||||||
postcard::from_bytes(
|
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()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user