solana/src/fetch_stage.rs

44 lines
1.2 KiB
Rust
Raw Normal View History

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