use crate::error::MctxError;
use crate::raw_ip::platform::{RawIpTransmitSocket, open_raw_ip_socket, send_ip_datagram};
use crate::raw_ip::{RawIpSendReport, RawIpSocketConfig};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct RawIpPublicationId(pub u64);
#[derive(Debug)]
pub struct RawIpPublication {
id: RawIpPublicationId,
config: RawIpSocketConfig,
socket: RawIpTransmitSocket,
}
impl RawIpPublication {
pub fn new(id: RawIpPublicationId, config: RawIpSocketConfig) -> Result<Self, MctxError> {
let socket = open_raw_ip_socket(&config)?;
Ok(Self { id, config, socket })
}
pub fn id(&self) -> RawIpPublicationId {
self.id
}
pub fn config(&self) -> &RawIpSocketConfig {
&self.config
}
pub fn send_ip_datagram(&self, ip_datagram: &[u8]) -> Result<RawIpSendReport, MctxError> {
send_ip_datagram(&self.socket, self.id, ip_datagram)
}
}