Skip to content

Commit

Permalink
refactor: allow setters to be used on shared socket
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcsmith committed Dec 13, 2023
1 parent 96b9dbd commit 2a358b6
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 92 deletions.
17 changes: 11 additions & 6 deletions crates/scion/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,23 @@ pub struct DispatcherStream {
}

impl DispatcherStream {
/// Create a new DispatcherStream over an already connected UnixStream.
pub fn new(stream: UnixStream) -> Self {
Self {
inner: stream,
send_buffer: BytesMut::with_capacity(SEND_BUFFER_LEN),
recv_buffer: BytesMut::with_capacity(RECV_BUFFER_LEN),
parser: StreamParser::new(),
}
}

/// Connects to the dispatcher over a Unix socket at the provided path.
pub async fn connect<P: AsRef<Path> + std::fmt::Debug>(path: P) -> Result<Self, io::Error> {
tracing::trace!(?path, "connecting to dispatcher");
let inner = UnixStream::connect(path).await?;
tracing::trace!("successfully connected");

Ok(Self {
inner,
send_buffer: BytesMut::with_capacity(SEND_BUFFER_LEN),
recv_buffer: BytesMut::with_capacity(RECV_BUFFER_LEN),
parser: StreamParser::new(),
})
Ok(Self::new(inner))
}

/// Register to receive SCION packet for the given address and port.
Expand Down
Loading

0 comments on commit 2a358b6

Please sign in to comment.