diff --git a/examples/calculator.rs b/examples/calculator.rs index b436d71..5fce2fa 100644 --- a/examples/calculator.rs +++ b/examples/calculator.rs @@ -44,8 +44,8 @@ fn receive<'a>( while let Ok(packet) = recv.try_recv() { if !drop_packet() { match packet { - PacketType::EmptyReply { reply_no } => { - let _ = seq.receive_empty_reply(reply_no); + PacketType::Ack { reply_no } => { + let _ = seq.receive_ack(reply_no); } PacketType::Payload { seq_no, reply_no, payload } => { for RecvSuccess { guard, packet, send_data } in seq.receive_iter(transport, seq_no, reply_no, payload) { diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 885290e..ef3716d 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -39,8 +39,8 @@ fn process(guard: ReplyGuard<'_, &MpscTransport>, recv_packet: Packet, s fn receive<'a>(recv: &Receiver>, seq: &SeqExSync<&'a MpscTransport>, transport: &'a MpscTransport) { match recv.recv().unwrap() { - PacketType::EmptyReply { reply_no } => { - let result = seq.receive_empty_reply(reply_no); + PacketType::Ack { reply_no } => { + let result = seq.receive_ack(reply_no); if let Ok(Exclamation) = result { // Our Hello World exchange ends right here. print!("\n"); diff --git a/src/seq_queue.rs b/src/seq_queue.rs index 8a94c16..fb334c3 100644 --- a/src/seq_queue.rs +++ b/src/seq_queue.rs @@ -64,7 +64,7 @@ pub struct SeqEx { concurrent_replies: [SeqNo; CAP], /// The total number of concurrent replies being processed. When a packet is received, a reply /// number is issued for that packet. That reply number reserves resources for itself, so that - /// when `reply_raw` or `reply_empty_raw` are called with it, they are guaranteed not to fail. + /// when `reply_raw` or `ack_raw` are called with it, they are guaranteed not to fail. /// To accomplish this we must track all issued reply numbers. concurrent_replies_total: usize, } @@ -158,7 +158,7 @@ impl SeqEx { /// /// If the return value is `Err` the queue is full and the packet will not be sent. /// The caller must either cancel sending, abort the connection, or wait until a call to - /// `receive` or `receive_empty_reply` returns `Ok` and try again. + /// `receive` or `receive_ack` returns `Ok` and try again. /// /// If `Ok` is returned then the packet was successfully sent. /// @@ -209,13 +209,13 @@ impl SeqEx { let is_next = normalized_seq_no == 0; if is_below_range { // If it is below the range, that means the packet has been received twice. - // For every received packet we either send a normal reply or send an empty reply. + // For every received packet we either send a normal reply or send an ack. // If the application sent a normal reply in response to this packet previously, and // that reply has not been acknowledged, then arg `seq_no` will be in the send window, // and if the application is still deciding what to reply with, it will be in the // concurrent replies array. // If either are the case then we know we will eventually send a reply to the packet. - // If neither are the case then we must send an empty reply so the remote peer can stop + // If neither are the case then we must send an ack so the remote peer can stop // resending the packet. for entry in self.send_window.iter().flatten() { if entry.reply_no == Some(seq_no) { @@ -227,7 +227,7 @@ impl SeqEx { return Err(Error::OutOfSequence); } } - app.send_empty_reply(seq_no); + app.send_ack(seq_no); return Err(Error::OutOfSequence); } else if is_above_range { return Err(Error::OutOfSequence); @@ -270,7 +270,7 @@ impl SeqEx { } } } - pub fn receive_empty_reply(&mut self, reply_no: SeqNo) -> Result { + pub fn receive_ack(&mut self, reply_no: SeqNo) -> Result { let slot = self.send_window_slot_mut(reply_no); if slot.as_ref().map_or(false, |e| e.seq_no == reply_no) { let entry = slot.take().unwrap(); @@ -352,11 +352,11 @@ impl SeqEx { app.send(entry.seq_no, entry.reply_no, &entry.data); } } - pub fn reply_empty_raw(&mut self, mut app: TL, reply_no: SeqNo) { + pub fn ack_raw(&mut self, mut app: TL, reply_no: SeqNo) { if self.remove_reservation(reply_no) { - // Empty replies are only sent once. There is code in `receive_raw` to handle resending - // an empty reply in the event that the first one here was dropped by the network. - app.send_empty_reply(reply_no); + // Acks are only sent once. There is code in `receive_raw` to handle resending + // an ack in the event that the first one here was dropped by the network. + app.send_ack(reply_no); } } fn remove_reservation(&mut self, reply_no: SeqNo) -> bool { diff --git a/src/single_thread.rs b/src/single_thread.rs index 2b17dbc..935a987 100644 --- a/src/single_thread.rs +++ b/src/single_thread.rs @@ -14,7 +14,7 @@ impl<'a, TL: TransportLayer> ReplyGuard<'a, TL> { } impl<'a, TL: TransportLayer> Drop for ReplyGuard<'a, TL> { fn drop(&mut self) { - self.0.reply_empty_raw(self.1.clone(), self.2) + self.0.ack_raw(self.1.clone(), self.2) } } diff --git a/src/sync.rs b/src/sync.rs index e686b69..63e8b37 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -36,7 +36,7 @@ impl<'a, TL: TransportLayer, const CAP: usize> ReplyGuard<'a, TL, CAP> { impl<'a, TL: TransportLayer, const CAP: usize> Drop for ReplyGuard<'a, TL, CAP> { fn drop(&mut self) { let mut seq = self.0.seq_ex.lock().unwrap(); - seq.reply_empty_raw(self.1.clone(), self.2); + seq.ack_raw(self.1.clone(), self.2); } } @@ -108,8 +108,8 @@ impl SeqExSync { } } - pub fn receive_empty_reply(&self, reply_no: SeqNo) -> Result { - let ret = self.lock().receive_empty_reply(reply_no); + pub fn receive_ack(&self, reply_no: SeqNo) -> Result { + let ret = self.lock().receive_ack(reply_no); self.unblock(ret.is_ok()); ret } @@ -153,7 +153,7 @@ pub enum PacketType { reply_no: Option, payload: Payload, }, - EmptyReply { + Ack { reply_no: SeqNo, }, } @@ -183,7 +183,7 @@ impl TransportLayer for &MpscTransport { fn send(&mut self, seq_no: SeqNo, reply_no: Option, payload: &Payload) { let _ = self.channel.send(PacketType::Payload { seq_no, reply_no, payload: payload.clone() }); } - fn send_empty_reply(&mut self, reply_no: SeqNo) { - let _ = self.channel.send(PacketType::EmptyReply { reply_no }); + fn send_ack(&mut self, reply_no: SeqNo) { + let _ = self.channel.send(PacketType::Ack { reply_no }); } } diff --git a/src/transport_layer.rs b/src/transport_layer.rs index b621615..4e3c312 100644 --- a/src/transport_layer.rs +++ b/src/transport_layer.rs @@ -15,5 +15,5 @@ pub trait TransportLayer: Clone { fn update_service_time(&mut self, timestamp: i64, current_time: i64) {} fn send(&mut self, seq_no: SeqNo, reply_no: Option, payload: &Self::SendData); - fn send_empty_reply(&mut self, reply_no: SeqNo); + fn send_ack(&mut self, reply_no: SeqNo); }