mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
fix regression in xous-names blocking connect
The `libstd` implementation has a bug where it was going through a vector and mutating it by removing items from the vector, but not updating the indices. This fix goes through the vector in reverse order, so that removed items don't affect the position of the next items in iteration order. This seems to make the blocking connect much more stable.
This commit is contained in:
parent
21778f5895
commit
f2068f2c89
2 changed files with 32 additions and 41 deletions
|
|
@ -161,12 +161,6 @@ impl XousNames {
|
||||||
/// This call uses the API already in place in `libstd`, hence the different style of
|
/// This call uses the API already in place in `libstd`, hence the different style of
|
||||||
/// argument passing, and tons of `unsafe` code.
|
/// argument passing, and tons of `unsafe` code.
|
||||||
pub fn request_connection_blocking(&self, name: &str) -> Result<xous::CID, xous::Error> {
|
pub fn request_connection_blocking(&self, name: &str) -> Result<xous::CID, xous::Error> {
|
||||||
match self.request_connection(name) { // try a direct connection first
|
|
||||||
Ok(val) => Ok(val),
|
|
||||||
Err(xous::Error::AccessDenied) => Err(xous::Error::AccessDenied),
|
|
||||||
_ => {
|
|
||||||
// if it fails, yield the slice, and then register ourselves for the blocking path
|
|
||||||
xous::yield_slice();
|
|
||||||
let mut cr: ConnectRequest = Default::default();
|
let mut cr: ConnectRequest = Default::default();
|
||||||
let name_bytes = name.as_bytes();
|
let name_bytes = name.as_bytes();
|
||||||
|
|
||||||
|
|
@ -178,7 +172,7 @@ impl XousNames {
|
||||||
for (&src_byte, dest_byte) in name_bytes.iter().zip(&mut cr.name) {
|
for (&src_byte, dest_byte) in name_bytes.iter().zip(&mut cr.name) {
|
||||||
*dest_byte = src_byte;
|
*dest_byte = src_byte;
|
||||||
}
|
}
|
||||||
log::info!("connection requested {}", name);
|
log::debug!("connection requested {}", name);
|
||||||
let msg = xous::MemoryMessage {
|
let msg = xous::MemoryMessage {
|
||||||
id: api::Opcode::BlockingConnect.to_usize().unwrap(),
|
id: api::Opcode::BlockingConnect.to_usize().unwrap(),
|
||||||
buf: unsafe{ // safety: `cr` is #[repr(C, align(4096))], and should be exactly on page in size
|
buf: unsafe{ // safety: `cr` is #[repr(C, align(4096))], and should be exactly on page in size
|
||||||
|
|
@ -194,14 +188,12 @@ impl XousNames {
|
||||||
|
|
||||||
if result == 0 {
|
if result == 0 {
|
||||||
let cid = unsafe { response_ptr.add(1).read() }.into(); // safety: because that's how it was packed on the server
|
let cid = unsafe { response_ptr.add(1).read() }.into(); // safety: because that's how it was packed on the server
|
||||||
log::info!("connected to {}:{}", name, cid);
|
log::debug!("connected to {}:{}", name, cid);
|
||||||
Ok(cid)
|
Ok(cid)
|
||||||
} else {
|
} else {
|
||||||
Err(xous::Error::InternalError)
|
Err(xous::Error::InternalError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if every server that specified a `max_conn` count has filled
|
/// Returns `true` if every server that specified a `max_conn` count has filled
|
||||||
/// every slot available. Once all the limited slots are filled, the system has
|
/// every slot available. Once all the limited slots are filled, the system has
|
||||||
|
|
|
||||||
|
|
@ -437,10 +437,10 @@ fn main() -> ! {
|
||||||
// See if we have any requests matching this server ID. If so, make the
|
// See if we have any requests matching this server ID. If so, make the
|
||||||
// connection. Note that this could be replaced by `drain_filter()` when
|
// connection. Note that this could be replaced by `drain_filter()` when
|
||||||
// that is stabilized
|
// that is stabilized
|
||||||
let mut i = 0;
|
let mut i = waiting_connections.len() as isize - 1;
|
||||||
while i < waiting_connections.len() {
|
while i >= 0 {
|
||||||
if name_from_msg(&waiting_connections[i]) == Ok(name) {
|
if name_from_msg(&waiting_connections[i as usize]) == Ok(name) {
|
||||||
let mut msg = waiting_connections.remove(i);
|
let mut msg = waiting_connections.remove(i as usize);
|
||||||
match blocking_connect(&mut msg, &mut name_table) {
|
match blocking_connect(&mut msg, &mut name_table) {
|
||||||
Err(e) => respond_connect_error(msg, e),
|
Err(e) => respond_connect_error(msg, e),
|
||||||
Ok(ConnectSuccess::Connected(cid, disc)) => {
|
Ok(ConnectSuccess::Connected(cid, disc)) => {
|
||||||
|
|
@ -450,9 +450,8 @@ fn main() -> ! {
|
||||||
panic!("message connection attempt resulted in `Wait` even though it ought to exist");
|
panic!("message connection attempt resulted in `Wait` even though it ought to exist");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
|
i -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue