-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: unifying how unix/tcp streams are handled in ninep clients …
…and servers
- Loading branch information
Showing
7 changed files
with
92 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,38 @@ | ||
//! A simple 9p Protocol implementation for serving filesystem interfaces | ||
use std::{ | ||
io::{Read, Write}, | ||
net::TcpStream, | ||
os::unix::net::UnixStream, | ||
}; | ||
|
||
pub mod client; | ||
pub mod fs; | ||
pub mod protocol; | ||
pub mod server; | ||
|
||
use protocol::{Format9p, Rdata, Rmessage}; | ||
|
||
pub type Result<T> = std::result::Result<T, String>; | ||
|
||
pub trait Stream: Read + Write + Send + Sized + 'static { | ||
/// The underlying try_clone implementations for file descriptors can fail at the libc level so | ||
/// we need to account for that here. | ||
fn try_clone(&self) -> Result<Self>; | ||
|
||
fn reply(&mut self, tag: u16, resp: Result<Rdata>) { | ||
let r: Rmessage = (tag, resp).into(); | ||
let _ = r.write_to(self); | ||
} | ||
} | ||
|
||
impl Stream for UnixStream { | ||
fn try_clone(&self) -> Result<Self> { | ||
self.try_clone().map_err(|e| e.to_string()) | ||
} | ||
} | ||
|
||
impl Stream for TcpStream { | ||
fn try_clone(&self) -> Result<Self> { | ||
self.try_clone().map_err(|e| e.to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters