I am trying to get data out of a scoped thread in crossbeam but I get this error
let s = sender.clone();
| - lifetime `'1` appears in the type of `s`
...
55 | let response = sess.getbulk(
| ^^^^ `sess` was mutably borrowed here in the previous iteration of the loop
...
81 | s.send((agent, n)).unwrap();
| ------------------ argument requires that `sess` is borrowed for `'1`
I have never seen lifetime '1.
The code is below:
n get_bulk( agents: &[&str], community: &[u8], timeout: Duration, non_repeat: u32, max_repetitions: u32, oids: &[&[u32]]) {
/// The community string and timeout need to be moved to main
///
/// non_repeat is the number of non-repeaters
/// Think in terms of row from table and each oid a column in the table
/// Which they actually are in
let mut row = 1u32;
let cols = oids.len();
let (sender, receiver) = mpsc::channel();
/// Use crossbeam crate. Place each device for query
/// into Crossbeam scope for parallel processing.
crossbeam::scope(|scope| {
for agent in agents {
let s = sender.clone();
scope.spawn(move |_| {
let mut collected_oids: Vec<Vec<u32>> = oids.iter().map(|&s| s.to_owned()).collect();
let mut sess = SyncSession::new(
agent, community, Some(timeout), 0).unwrap();
let mut end_of_column = 0;
while end_of_column < cols {
let mut oids_for_getbulk: Vec<&[u32]> = collected_oids.iter().map(|s| &s[..]).collect();
let response = sess.getbulk(
&oids_for_getbulk,
non_repeat, max_repetitions).unwrap();
let mut col = 0_usize;
for (name, val) in response.varbinds {
let n = name.clone();
//let v: = val.clone();
if col == cols {
col = 0;
row += 1;
}
/// Find the last table row and add those each column's
/// objectidentifiers to the new oids
let oid: String = oids[col].iter().map(|x| x.to_string() + ".").collect();
/// TODO needs to be logged, not printed
/// Keep track of fails. Remember, if snmp querying two
/// adjacent columns, at some point the next column
/// will be queried but should fail as you've already
/// queried it.
if !name.to_string().starts_with(&oid) {
println!("Failed: {} => {}", oid, name);
}
if name.to_string().starts_with(&oid) {
s.send((agent, n)).unwrap();
println!("{}. {} {} => {:?}", row, agent, name, val);
let next_getbulk = name.to_string()
.split('.')
.map(|c| c.parse::<u32>().unwrap())
.collect::<Vec<u32>>();
collected_oids[col] = next_getbulk;
if col == cols - 1 {
row += 1;
}
} else {
end_of_column += 1;
println!("End of column: {} => cols: {}", end_of_column, cols);
if !end_of_column < cols {
break;
}
}
col += 1;
}
}
});
}
}).unwrap();
for (a, o) in receiver.iter() {
println!("Received: {}: {}", a, o);
}
}