Skip to content

Commit b20beea

Browse files
committed
debug log machine events as they happen
1 parent 88c63f5 commit b20beea

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

core/src/range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::str::FromStr;
44
use thiserror::Error;
55

66
/// A range of IPv4 addresses with a common prefix
7-
#[derive(Clone, Copy)]
7+
#[derive(Clone, Copy, PartialEq, Eq)]
88
pub struct Ipv4Range {
99
addr: Ipv4Addr,
1010
bits: u8,

machine/src/lib.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct Machine<C, E> {
6666
impl<C, E> Machine<C, E>
6767
where
6868
C: Display + Send + 'static,
69-
E: FromStr + Send + 'static,
69+
E: FromStr + Display + Send + 'static,
7070
E::Err: std::fmt::Debug + Display + Send + Sync,
7171
{
7272
pub async fn new(id: MachineId, plug: Plug, cmd: Command) -> Self {
@@ -138,24 +138,12 @@ impl<C, E> Machine<C, E> {
138138
pub fn namespace(&self) -> Namespace {
139139
self.ns
140140
}
141-
}
142-
143-
impl<C, E: Display> Machine<C, E> {
144-
async fn do_recv(&mut self) -> Option<E> {
145-
let ev = self.rx.next().await;
146-
if let Some(ref ev) = ev {
147-
log::info!("{} {}", self.id, ev);
148-
} else {
149-
log::info!("{} event stream closed", self.id);
150-
}
151-
ev
152-
}
153141

154142
pub async fn recv(&mut self) -> Option<E> {
155143
if let Some(ev) = self.buffer.pop_front() {
156144
Some(ev)
157145
} else {
158-
self.do_recv().await
146+
self.rx.next().await
159147
}
160148
}
161149

@@ -173,7 +161,7 @@ impl<C, E: Display> Machine<C, E> {
173161
return Some(res);
174162
}
175163
loop {
176-
match self.do_recv().await {
164+
match self.rx.next().await {
177165
Some(ev) => {
178166
if let Some(res) = f(&ev) {
179167
return Some(res);
@@ -196,7 +184,7 @@ impl<C, E: Display> Machine<C, E> {
196184
}
197185
}
198186
loop {
199-
match self.do_recv().await {
187+
match self.rx.next().await {
200188
Some(ev) => {
201189
if let Some(res) = f(&ev) {
202190
return Some(res);
@@ -227,7 +215,7 @@ fn machine<C, E>(
227215
) -> thread::JoinHandle<Result<()>>
228216
where
229217
C: Display + Send + 'static,
230-
E: FromStr + Send + 'static,
218+
E: FromStr + Display + Send + 'static,
231219
E::Err: std::fmt::Debug + Display + Send + Sync,
232220
{
233221
thread::spawn(move || {
@@ -333,6 +321,7 @@ where
333321
Ok(ev) => ev,
334322
Err(err) => return Err(Error::new(ErrorKind::Other, err.to_string())),
335323
};
324+
log::debug!("{} {}", id, ev);
336325
if event.unbounded_send(ev).is_err() {
337326
break;
338327
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<C, E> Default for Netsim<C, E> {
5252
impl<C, E> Netsim<C, E>
5353
where
5454
C: Display + Send + 'static,
55-
E: FromStr + Send + 'static,
55+
E: FromStr + Display + Send + 'static,
5656
E::Err: std::fmt::Debug + Display + Send + Sync,
5757
{
5858
pub fn new() -> Self {

0 commit comments

Comments
 (0)