From 73570b0926107d958cc406f26cea86d70d756a57 Mon Sep 17 00:00:00 2001 From: Tiago Lam Date: Sat, 8 Feb 2020 10:24:57 +0000 Subject: [PATCH 1/2] Revert "chan: Support opening "empty" ChanScheme." This reverts commit 9526ffa80fb1ffcfd242e09803ee87d31fdc1073. --- src/chan.rs | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/src/chan.rs b/src/chan.rs index f9b3f1ccb8..86f64ae39e 100644 --- a/src/chan.rs +++ b/src/chan.rs @@ -40,10 +40,6 @@ impl Default for Connection { } } -pub struct NullFile { - pub flags: usize, -} - #[derive(Debug, Default)] pub struct Handle { id: usize, @@ -97,7 +93,6 @@ impl Handle { } pub struct ChanScheme { - nulls: HashMap, handles: HashMap, listeners: HashMap, next_id: usize, @@ -106,7 +101,6 @@ pub struct ChanScheme { impl ChanScheme { pub fn new() -> io::Result { Ok(Self { - nulls: HashMap::new(), handles: HashMap::new(), listeners: HashMap::new(), next_id: 0, @@ -131,20 +125,6 @@ impl SchemeBlockMut for ChanScheme { let path = ::std::str::from_utf8(path).or(Err(Error::new(EPERM)))?; let new_id = self.next_id; - - if path.is_empty() { - let null = NullFile { - flags: flags, - }; - - let id = new_id; - - self.nulls.insert(id, null); - self.next_id += 1; - - return Ok(Some(id)); - } - let mut new = Handle::default(); new.flags = flags; @@ -175,13 +155,6 @@ impl SchemeBlockMut for ChanScheme { Ok(Some(new_id)) } fn dup(&mut self, id: usize, buf: &[u8]) -> Result> { - if let Some(flags) = self.nulls - .get(&id) - .map(|null| null.flags) - { - return self.open(buf, flags, 0, 0); - } - match buf { b"listen" => { loop { @@ -316,10 +289,6 @@ impl SchemeBlockMut for ChanScheme { } } fn close(&mut self, id: usize) -> Result> { - if let Some(_null) = self.nulls.remove(&id) { - return Ok(Some(0)); - } - let handle = self.handles.remove(&id).ok_or(Error::new(EBADF))?; match handle.extra { From ea4247c0b5390fd8b91e9c345757ad99fe692d35 Mon Sep 17 00:00:00 2001 From: Tiago Lam Date: Sat, 8 Feb 2020 10:29:52 +0000 Subject: [PATCH 2/2] chan: Support turning unnamed into named sockets. Previous approach, reverted in commit c7cf2ca, would break unnamed sockets - since it assumed there would always be an interim step were one would first name an unnamed socket, before "listen" / "connect". Instead of using the same approach as the "tcp:" scheme in Redox's netstack, which requires an extra mapping of temporary unnamed sockets, handle the different use cases in dup(). Thus, if a "buf" is provided that's not a "connect" or "listen", it must be a new path for turning the unnamed socket into a named socket and should be handled as such. --- src/chan.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/chan.rs b/src/chan.rs index 86f64ae39e..db20f7ad28 100644 --- a/src/chan.rs +++ b/src/chan.rs @@ -211,7 +211,20 @@ impl SchemeBlockMut for ChanScheme { Ok(Some(new_id)) }, _ => { - return Err(Error::new(EBADF)); + // If a buf is provided, different than "connect" / "listen", + // turn the socket into a named socket. + + if buf == b"" { + return Err(Error::new(EBADF)); + } + + let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?; + if handle.path.is_some() { + return Err(Error::new(EBADF)); + } + + let flags = handle.flags; + return self.open(buf, flags, 0, 0); } } }