diff --git a/lib/tftp/tftp.rb b/lib/tftp/tftp.rb index 86ee945..8d0dd86 100644 --- a/lib/tftp/tftp.rb +++ b/lib/tftp/tftp.rb @@ -129,15 +129,18 @@ def send(tag, sock, io) log :warn, "#{tag} Timeout at block ##{seq}" return end - msg, _ = sock.recvfrom(4, 0) - pkt = Packet.parse(msg) - if pkt.class != Packet::ACK - log :warn, "#{tag} Expected ACK but got: #{pkt.class}" - return - end - if pkt.seq != seq - log :warn, "#{tag} Seq mismatch: #{seq} != #{pkt.seq}" - return + loop do + msg, _ = sock.recvfrom(4, 0) + pkt = Packet.parse(msg) + if pkt.class != Packet::ACK + log :warn, "#{tag} Expected ACK but got: #{pkt.class}" + return + end + break if pkt.seq == seq + if pkt.seq > seq + log :warn, "#{tag} Seq mismatch: #{seq} != #{pkt.seq}" + return + end end # Increment with wrap around at 16 bit boundary, # because of tftp block number field size limit.