class TFTP::Receive

Public Class Methods

new(connection, peer_addr, peer_port, listener) click to toggle source

Receive a file from the peer

Calls superclass method TFTP::Transfer::new
# File lib/em-tftp.rb, line 195
def initialize(connection, peer_addr, peer_port, listener)
  super(connection, peer_addr, peer_port, listener)
  @buffer = ""
  @block_no = 1
end

Public Instance Methods

ack(packet, port) click to toggle source
# File lib/em-tftp.rb, line 218
def ack(packet, port)
  abort!(4, "Received unexpected TFTP ACK packet while receiving file")
end
data(packet, port) click to toggle source
# File lib/em-tftp.rb, line 201
def data(packet, port)
  if packet.block_no == @block_no
    stop_timer!
    if @peer_port.nil?
      @peer_port = port
    end
    if packet.data.size > 0
      @listener.received_block(packet.data)
    end
    if packet.data.size < 512
      finished!
    else
      send_ack(@block_no)
      @block_no += 1
    end
  end
end