about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml1
-rw-r--r--src/facility/i3.rs24
3 files changed, 28 insertions, 9 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0edf3ea..ccf64c0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -69,6 +69,17 @@ dependencies = [
 ]
 
 [[package]]
+name = "async-net"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b948000fad4873c1c9339d60f2623323a0cfd3816e5181033c6a5cb68b2accf7"
+dependencies = [
+ "async-io",
+ "blocking",
+ "futures-lite",
+]
+
+[[package]]
 name = "async-task"
 version = "4.7.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -335,6 +346,7 @@ dependencies = [
  "async-executor",
  "async-fs",
  "async-io",
+ "async-net",
  "bitflags",
  "futures-lite",
  "json-event-parser",
diff --git a/Cargo.toml b/Cargo.toml
index 8e91a58..72f5d3b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,6 +8,7 @@ edition = "2024"
 async-channel = "2.0.0"
 async-fs = "2.0.0"
 async-io = "2.1.0"
+async-net = "2.0.0"
 libc = "0.2.191"
 json-event-parser = "0.2.3"
 futures-lite = "2.0.0"
diff --git a/src/facility/i3.rs b/src/facility/i3.rs
index 4b91b02..c2f9878 100644
--- a/src/facility/i3.rs
+++ b/src/facility/i3.rs
@@ -6,13 +6,14 @@ use crate::xdg::xdg_runtime_directory;
 use std::any::Any;
 use std::path::{ Path, PathBuf };
 
-use async_fs::{ metadata, read_dir, File, OpenOptions };
+use async_fs::{ metadata, read_dir };
 use async_fs::unix::FileTypeExt;
+use async_net::unix::UnixStream;
 use futures_lite::StreamExt;
 
 
 pub struct I3 {
-  socket: File,
+  socket: UnixStream,
 }
 
 
@@ -37,7 +38,7 @@ impl CreatableFacility for I3 {
 }
 
 impl I3 {
-  async fn find_socket() -> Result<File> {
+  async fn find_socket() -> Result<UnixStream> {
     /*   We save most errors for the end, because they aren't really errors if
      * a subsequent attempt succeeds.
      */
@@ -97,7 +98,7 @@ impl I3 {
    * for subdirectories with names having a specific pattern. Do that.
    */
   async fn try_tmp_directory(path: &Path, username: &str)
-    -> Result<Option<File>>
+    -> Result<Option<UnixStream>>
   {
     let mut directory = read_dir(path).await?;
 
@@ -135,7 +136,7 @@ impl I3 {
    *   The directory iteration logic is a lot like that for try_tmp_directory().
    * In principle, it could make sense to write a helper.
    */
-  async fn try_socket_directory(path: &Path) -> Result<Option<File>> {
+  async fn try_socket_directory(path: &Path) -> Result<Option<UnixStream>> {
     let mut directory = read_dir(path).await?;
 
     while let Some(entry) = directory.try_next().await? {
@@ -165,15 +166,20 @@ impl I3 {
   }
 
   /* If we have a candidate full path to an i3 socket, see if it works. */
-  async fn try_socket_path(path: &Path) -> Result<Option<File>> {
+  async fn try_socket_path(path: &Path) -> Result<Option<UnixStream>> {
     /* Do follow symlinks, for the socket check. */
     if !metadata(path).await?.file_type().is_socket() {
       return Ok(None);
     }
 
-    /* Unix-domain sockets don't use open(), despite appearing in the filesystem. TODO */
-    let socket = OpenOptions::new().read(true).write(true).open(path).await?;
-    println!("got i3 socket {:?}", path);
+    /*   Unix-domain sockets don't use open(), despite appearing in the
+     * filesystem. If you think about it, that makes sense: Each process that
+     * opens it gets its own send/receive pair. It's not like a pipe.
+     */
+    let socket = UnixStream::connect(path).await?;
+
+    println!("Found i3 socket {}", path.display());
+
     Ok(Some(socket))
   }
 }