I've read everything I can find but I just don't understand where these things are supposed to go or maybe I just made a mistake and don't need them at all. The fn reader_start() at the end kicks it all off.
//==================================================================================
// Runtime object for thread
pub struct UDPRData{
receiver : crossbeam_channel::Receiver<messages::ReaderMsg>,
p_sock : & socket2::Socket,
p_addr : & socket2::SockAddr,
udp_frame : [MaybeUninit<u8>; common_defs::FRAME_SZ],
prot_frame : [u8; common_defs::PROT_SZ*2],
//pub i_cc: protocol::cc_in::CCDataMutex,
pub i_seq: protocol::seq_in::SeqData,
listen: bool,
}
// Implementation methods on UDPRData
impl UDPRData {
// Create a new instance and initialise the default arrays
pub fn new(receiver : crossbeam_channel::Receiver<messages::ReaderMsg>, p_sock : & socket2::Socket, p_addr : & socket2::SockAddr) -> UDPRData {
// Create an instance of the cc_in type
//let i_cc = protocol::cc_in::CCDataMutex::new();
// Create an instance of the sequence type
let i_seq = protocol::seq_in::SeqData::new();
UDPRData {
receiver: receiver,
p_sock: p_sock,
p_addr: p_addr,
udp_frame: unsafe {MaybeUninit::uninit().assume_init()},
prot_frame: [0; common_defs::PROT_SZ*2],
//i_cc: i_cc,
i_seq: i_seq,
listen: false,
}
}
// Run loop for reader
pub fn reader_run(&mut self) {
loop {
thread::sleep(Duration::from_millis(100));
// Check for messages
let r = self.receiver.try_recv();
match r {
Ok(msg) => {
match msg {
messages::ReaderMsg::Terminate => break,
messages::ReaderMsg::StartListening => {
self.listen = true;
println!("Listening for data...");
}
};
},
// Do nothing if there are no message matches
_ => (),
};
// Check for read data
if self.listen {
let r = self.p_sock.recv_from(&mut self.udp_frame);
match r {
Ok((_sz,_addr)) => {
//println!("Received {:?} data bytes", sz);
self.split_frame();
}
Err(_e) => (), //println!("Error or timeout on receive data [{}]", e),
}
}
}
}
// Split frame into protocol fields and data content and decode
fn split_frame(&mut self) {
// TBD
protocol::decoder::frame_decode(126, 1, 48000, common_defs::FRAME_SZ*2, self.udp_frame);
}
}
//==================================================================================
// Thread startup
pub fn reader_start(receiver : crossbeam_channel::Receiver<messages::ReaderMsg>, p_sock : Arc<socket2::Socket>, p_addr : Arc<socket2::SockAddr>) {
thread::spawn( move || {
reader_run(receiver, &p_sock, &p_addr);
});
}
fn reader_run(receiver : crossbeam_channel::Receiver<messages::ReaderMsg>, p_sock : &socket2::Socket, p_addr : &socket2::SockAddr) {
println!("UDP Reader running");
// Instantiate the runtime object
let mut i_reader = UDPRData::new(receiver, p_sock, p_addr);
// Exits when the reader loop exits
i_reader.reader_run();
println!("UDP Reader exiting");
thread::sleep(Duration::from_millis(1000));
}
error[E0106]: missing lifetime specifier
--> src\udp\udp_man\udp_reader.rs:42:12
|
42 | p_sock : & socket2::Socket,
| ^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
40 ~ pub struct UDPRData<'a>{
41 | receiver : crossbeam_channel::Receivermessages::ReaderMsg,
42 ~ p_sock : &'a socket2::Socket,
|
error[E0106]: missing lifetime specifier
--> src\udp\udp_man\udp_reader.rs:43:15
|
43 | p_addr : & socket2::SockAddr,
| ^ expected named lifetime parameter