Files
solana/src/fetch_stage.rs

44 lines
1.2 KiB
Rust
Raw Normal View History

2018-05-29 11:18:12 -06:00
//! The `fetch_stage` batches input from a UDP socket and sends it to a channel.
2018-06-27 12:33:56 -06:00
use packet::PacketRecycler;
2018-05-29 11:18:12 -06:00
use std::net::UdpSocket;
use std::sync::atomic::AtomicBool;
use std::sync::mpsc::channel;
use std::sync::Arc;
2018-05-29 11:18:12 -06:00
use std::thread::JoinHandle;
2018-06-27 12:33:56 -06:00
use streamer::{self, PacketReceiver};
2018-05-29 11:18:12 -06:00
pub struct FetchStage {
2018-06-27 12:33:56 -06:00
pub packet_receiver: PacketReceiver,
pub thread_hdls: Vec<JoinHandle<()>>,
2018-05-29 11:18:12 -06:00
}
impl FetchStage {
2018-06-27 12:33:56 -06:00
pub fn new(socket: UdpSocket, exit: Arc<AtomicBool>, packet_recycler: PacketRecycler) -> Self {
Self::new_multi_socket(vec![socket], exit, packet_recycler)
}
pub fn new_multi_socket(
sockets: Vec<UdpSocket>,
exit: Arc<AtomicBool>,
2018-06-27 12:33:56 -06:00
packet_recycler: PacketRecycler,
2018-05-29 11:18:12 -06:00
) -> Self {
let (packet_sender, packet_receiver) = channel();
let thread_hdls: Vec<_> = sockets
.into_iter()
.map(|socket| {
streamer::receiver(
socket,
exit.clone(),
packet_recycler.clone(),
packet_sender.clone(),
)
})
.collect();
2018-05-29 11:18:12 -06:00
FetchStage {
packet_receiver,
thread_hdls,
2018-05-29 11:18:12 -06:00
}
}
}