we connect now
This commit is contained in:
@@ -292,6 +292,13 @@ impl Instance {
|
|||||||
runtime_inner.spawn(func);
|
runtime_inner.spawn(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "async")]
|
||||||
|
pub fn spawn_async_blocking<F: Future<Output = impl Send + Sync + 'static> + Send + Sync + 'static>(&mut self, name: &str, func: F) {
|
||||||
|
self.threads.push(name.to_owned());
|
||||||
|
let runtime_inner = self.runtime.lock().unwrap();
|
||||||
|
runtime_inner.block_on(func);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn wait(&self) {
|
pub fn wait(&self) {
|
||||||
loop {
|
loop {
|
||||||
thread::sleep_ms(10000000)
|
thread::sleep_ms(10000000)
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> {
|
|||||||
// if the store is already opened, connect to the instance, that opened it and join
|
// if the store is already opened, connect to the instance, that opened it and join
|
||||||
// it's namespace
|
// it's namespace
|
||||||
info!("CONNECTING");
|
info!("CONNECTING");
|
||||||
|
unix_socket::connect(instance, store_path.into())?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -25,15 +25,17 @@ impl UnixListener {
|
|||||||
|
|
||||||
|
|
||||||
pub fn connect(instance: &mut Instance, store_path: PathBuf) -> MizeResult<()> {
|
pub fn connect(instance: &mut Instance, store_path: PathBuf) -> MizeResult<()> {
|
||||||
instance.spawn_async("unix_connection", connect_async(instance.clone(), store_path) );
|
instance.spawn_async_blocking("unix_connection", connect_async(instance.clone(), store_path) );
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn connect_async(mut instance: Instance, store_path: PathBuf) -> MizeResult<()> {
|
async fn connect_async(mut instance: Instance, store_path: PathBuf) -> MizeResult<()> {
|
||||||
let mut stream = UnixStream::connect(store_path).await?;
|
println!("we are never hereeeeeeeeeeeeee");
|
||||||
|
let mut stream = UnixStream::connect(store_path.join("sock")).await?;
|
||||||
let (read_half, write_half) = stream.split();
|
let (read_half, write_half) = stream.split();
|
||||||
|
println!("we are never hoooooooooooooooooooooooooooooo");
|
||||||
|
|
||||||
let (recieve_tx, recieve_rx) = unbounded::<MizeMessage>();
|
let (recieve_tx, recieve_rx) = unbounded::<MizeMessage>();
|
||||||
let (send_tx, send_rx) = unbounded::<MizeMessage>();
|
let (send_tx, send_rx) = unbounded::<MizeMessage>();
|
||||||
@@ -59,7 +61,7 @@ impl ConnListener for UnixListener {
|
|||||||
|
|
||||||
async fn unix_listen(listener: UnixListener, mut instance: Instance) -> MizeResult<()> {
|
async fn unix_listen(listener: UnixListener, mut instance: Instance) -> MizeResult<()> {
|
||||||
// remove the file at sock_path if it already exists
|
// remove the file at sock_path if it already exists
|
||||||
fs::remove_file(&listener.sock_path)?;
|
fs::remove_file(&listener.sock_path);
|
||||||
|
|
||||||
let listener = TokioUnixListener::bind(&listener.sock_path)
|
let listener = TokioUnixListener::bind(&listener.sock_path)
|
||||||
.mize_result_msg(format!("Could not bind to unix socket at '{}'", listener.sock_path.display()))?;
|
.mize_result_msg(format!("Could not bind to unix socket at '{}'", listener.sock_path.display()))?;
|
||||||
@@ -67,6 +69,7 @@ async fn unix_listen(listener: UnixListener, mut instance: Instance) -> MizeResu
|
|||||||
loop {
|
loop {
|
||||||
let (mut unix_sock, addr) = listener.accept().await
|
let (mut unix_sock, addr) = listener.accept().await
|
||||||
.mize_result_msg("Error while accepting Unix sock connection")?;
|
.mize_result_msg("Error while accepting Unix sock connection")?;
|
||||||
|
info!("new connection");
|
||||||
|
|
||||||
let (recieve_tx, recieve_rx) = unbounded::<MizeMessage>();
|
let (recieve_tx, recieve_rx) = unbounded::<MizeMessage>();
|
||||||
let (send_tx, send_rx) = unbounded::<MizeMessage>();
|
let (send_tx, send_rx) = unbounded::<MizeMessage>();
|
||||||
|
|||||||
Reference in New Issue
Block a user