Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Make internal Request an enum
Browse files Browse the repository at this point in the history
Also drop tuple conversions; preparing for a Batch variant.
  • Loading branch information
stbuehler committed Nov 25, 2021
1 parent a937896 commit bf0f6ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
12 changes: 10 additions & 2 deletions netlink-proto/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ where
destination: SocketAddr,
) -> Result<impl Stream<Item = NetlinkMessage<T>>, Error<T>> {
let (tx, rx) = unbounded::<NetlinkMessage<T>>();
let request = Request::from((message, destination, tx));
let request = Request::Single {
message,
destination,
metadata: tx,
};
debug!("handle: forwarding new request to connection");
UnboundedSender::unbounded_send(&self.requests_tx, request).map_err(|e| {
// the channel is unbounded, so it can't be full. If this
Expand All @@ -61,7 +65,11 @@ where
destination: SocketAddr,
) -> Result<(), Error<T>> {
let (tx, _rx) = unbounded::<NetlinkMessage<T>>();
let request = Request::from((message, destination, tx));
let request = Request::Single {
message,
destination,
metadata: tx,
};
debug!("handle: forwarding new request to connection");
UnboundedSender::unbounded_send(&self.requests_tx, request)
.map_err(|_| ErrorKind::ConnectionClosed.into())
Expand Down
2 changes: 1 addition & 1 deletion netlink-proto/src/protocol/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ where
}

pub fn request(&mut self, request: Request<T, M>) {
let Request {
let Request::Single {
mut message,
metadata,
destination,
Expand Down
34 changes: 6 additions & 28 deletions netlink-proto/src/protocol/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,10 @@ use netlink_packet_core::NetlinkMessage;
use crate::sys::SocketAddr;

#[derive(Debug)]
pub(crate) struct Request<T, M> {
pub metadata: M,
pub message: NetlinkMessage<T>,
pub destination: SocketAddr,
}

impl<T, M> From<(NetlinkMessage<T>, SocketAddr, M)> for Request<T, M>
where
T: Debug,
M: Debug,
{
fn from(parts: (NetlinkMessage<T>, SocketAddr, M)) -> Self {
Request {
message: parts.0,
destination: parts.1,
metadata: parts.2,
}
}
}

impl<T, M> From<Request<T, M>> for (NetlinkMessage<T>, SocketAddr, M)
where
T: Debug,
M: Debug,
{
fn from(req: Request<T, M>) -> (NetlinkMessage<T>, SocketAddr, M) {
(req.message, req.destination, req.metadata)
}
pub(crate) enum Request<T, M> {
Single {
metadata: M,
message: NetlinkMessage<T>,
destination: SocketAddr,
},
}

0 comments on commit bf0f6ad

Please sign in to comment.