solana/core/src/blob_fetch_stage.rs

47 lines
1.2 KiB
Rust
Raw Normal View History

//! The `blob_fetch_stage` pulls blobs from UDP sockets and sends it to a channel.
2018-12-07 19:16:27 -08:00
use crate::service::Service;
use crate::streamer::{self, BlobSender};
use std::net::UdpSocket;
2018-07-09 13:53:18 -07:00
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread::{self, JoinHandle};
pub struct BlobFetchStage {
2018-07-09 13:53:18 -07:00
exit: Arc<AtomicBool>,
thread_hdls: Vec<JoinHandle<()>>,
}
impl BlobFetchStage {
pub fn new(socket: Arc<UdpSocket>, sender: &BlobSender, exit: Arc<AtomicBool>) -> Self {
Self::new_multi_socket(vec![socket], sender, exit)
}
pub fn new_multi_socket(
sockets: Vec<Arc<UdpSocket>>,
sender: &BlobSender,
exit: Arc<AtomicBool>,
) -> Self {
let thread_hdls: Vec<_> = sockets
.into_iter()
.map(|socket| streamer::blob_receiver(socket, exit.clone(), sender.clone()))
.collect();
Self { exit, thread_hdls }
2018-07-09 13:53:18 -07:00
}
pub fn close(&self) {
self.exit.store(true, Ordering::Relaxed);
}
}
impl Service for BlobFetchStage {
type JoinReturnType = ();
fn join(self) -> thread::Result<()> {
for thread_hdl in self.thread_hdls {
thread_hdl.join()?;
}
Ok(())
}
}