Skip to content

Commit ced086b

Browse files
author
Nathan Cohen
committed
Changed connection to be immutable and limit number of messages on buffer to one
1 parent 996fa0b commit ced086b

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/connection.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,23 @@ where
8989
} = self;
9090
let mut socket = Pin::new(socket);
9191

92-
while !protocol.outgoing_messages.is_empty() {
92+
if !protocol.outgoing_messages.is_empty() {
9393
trace!(
9494
"found outgoing message to send checking if socket is ready"
9595
);
96-
if let Poll::Ready(Err(e)) = Pin::as_mut(&mut socket).poll_ready(cx)
97-
{
98-
// Sink errors are usually not recoverable. The socket
99-
// probably shut down.
100-
warn!("netlink socket shut down: {:?}", e);
101-
self.socket_closed = true;
102-
return;
96+
match Pin::as_mut(&mut socket).poll_ready(cx) {
97+
Poll::Ready(Err(e)) => {
98+
// Sink errors are usually not recoverable. The socket
99+
// probably shut down.
100+
warn!("netlink socket shut down: {:?}", e);
101+
self.socket_closed = true;
102+
return;
103+
}
104+
Poll::Pending => {
105+
trace!("poll is not ready, returning");
106+
return;
107+
}
108+
Poll::Ready(Ok(_)) => {}
103109
}
104110

105111
let (mut message, addr) =

src/handle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
/// message, the stream is
3636
/// closed
3737
pub fn request(
38-
&mut self,
38+
&self,
3939
message: NetlinkMessage<T>,
4040
destination: SocketAddr,
4141
) -> Result<impl Stream<Item = NetlinkMessage<T>>, Error<T>> {
@@ -59,7 +59,7 @@ where
5959
}
6060

6161
pub fn notify(
62-
&mut self,
62+
&self,
6363
message: NetlinkMessage<T>,
6464
destination: SocketAddr,
6565
) -> Result<(), Error<T>> {

0 commit comments

Comments
 (0)