Changeset - 526b221270eb
[Not reviewed]
0 1 0
Christopher Esterhuyse - 5 years ago 2020-07-23 15:39:51
christopher.esterhuyse@gmail.com
tightened visibility. cleaned up and simplified UDP mediator components
1 file changed with 9 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/ffi/pseudo_socket_api.rs
Show inline comments
 
use super::*;
 

	
 
use libc::{sockaddr, socklen_t};
 
use std::{
 
    collections::HashMap,
 
    ffi::c_void,
 
    net::SocketAddr,
 
    os::raw::c_int,
 
    sync::RwLock,
 
};
 
use std::{collections::HashMap, ffi::c_void, net::SocketAddr, os::raw::c_int, sync::RwLock};
 
///////////////////////////////////////////////////////////////////
 

	
 
struct FdAllocator {
 
    next: Option<c_int>,
 
    freed: Vec<c_int>,
 
}
 
enum ConnectorComplex {
 
    Setup {
 
        local: Option<SocketAddr>,
 
        peer: Option<SocketAddr>,
 
    },
 
    Communication {
 
        // Invariant: connector in communication state; native has this putter and getter only.
 
        connector: Connector,
 
        putter: PortId,
 
        getter: PortId,
 
    },
 
}
 
#[derive(Default)]
 
@@ -66,15 +61,20 @@ lazy_static::lazy_static! {
 
    static ref CC_MAP: RwLock<CcMap> = Default::default();
 
}
 
impl ConnectorComplex {
 
    fn try_become_connected(&mut self) {
 
        match self {
 
            ConnectorComplex::Setup { local: Some(local), peer: Some(peer) } => {
 
                // setup complete
 
                let mut connector = Connector::new(Box::new(crate::DummyLogger), crate::TRIVIAL_PD.clone(), Connector::random_id());
 
                // complete setup
 
                let mut connector = Connector::new(
 
                    Box::new(crate::DummyLogger),
 
                    crate::TRIVIAL_PD.clone(),
 
                    Connector::random_id(),
 
                );
 
                let [putter, getter] = connector.new_udp_mediator_component(*local, *peer).unwrap();
 
                connector.connect(None).unwrap();
 
                *self = ConnectorComplex::Communication { connector, putter, getter }
 
            }
 
            _ => {} // setup incomplete
 
        }
 
    }
 
}
0 comments (0 inline, 0 general)