use alloc::sync::Arc;
use ax_sync::Mutex;
use super::connection_manager::Connection;
use crate::{
NetError, NetResult,
general::GeneralOptions,
options::{Configurable, GetSocketOption, SetSocketOption},
state::{State, StateLock},
vsock::VsockConnId,
};
mod ops;
mod poll;
pub struct VsockStreamTransport {
conn_id: Mutex<Option<VsockConnId>>,
connection: Mutex<Option<Arc<Connection>>>,
state: StateLock,
general: GeneralOptions,
}
impl VsockStreamTransport {
pub fn new() -> Self {
Self {
conn_id: Mutex::new(None),
connection: Mutex::new(None),
state: StateLock::new(State::Idle),
general: GeneralOptions::new(1, 40, 0), }
}
fn get_connection(&self) -> NetResult<Arc<Connection>> {
self.connection.lock().clone().ok_or(NetError::NotConnected)
}
}
impl Default for VsockStreamTransport {
fn default() -> Self {
Self::new()
}
}
impl Configurable for VsockStreamTransport {
fn get_option_inner(&self, opt: &mut GetSocketOption) -> NetResult<bool> {
self.general.get_option_inner(opt)
}
fn set_option_inner(&self, opt: SetSocketOption) -> NetResult<bool> {
self.general.set_option_inner(opt)
}
}