class BBS::Zmodem::Input
The receiver’s side of the line as the Sender reads it: its bytes (telnet commands taken out by the session) kept until they make a header, at most MAX_PENDING of them; five CANs in a row cancel.
Public Class Methods
Source
# File lib/bbs/zmodem/input.rb, line 10 def initialize(session) @session = session @pending = [] @cans = 0 end
Reads from session (anything with BBS::Telnet#read_raw_byte).
Public Instance Methods
# File lib/bbs/zmodem/input.rb, line 20 def expect(*types, timeout: WAIT, ignore_timeout: false) deadline = monotonic + timeout loop do header = read_header(timeout: deadline - monotonic) return if header.nil? && ignore_timeout raise Timeout if header.nil? raise Cancelled if [ZCAN, ZABORT, ZFERR].include?(header.type) return header if types.include?(header.type) end end
Source
# File lib/bbs/zmodem/input.rb, line 33 def poll_header while (byte = @session.read_raw_byte(0)).is_a?(Integer) push(byte) end raise Hangup if byte.nil? scan_pending end
Takes what the receiver has sent so far without waiting, and returns the header it makes, if any.
# File lib/bbs/zmodem/input.rb, line 44 def read_header(timeout:, interruptible: false) deadline = monotonic + timeout loop do header = scan_pending return header if header byte = next_byte(deadline - monotonic) or return raise Cancelled if interruptible && CANCEL_KEYS.include?(byte) push(byte) end end
Waits up to timeout seconds for a header and returns it, or nil. With interruptible the caller’s Esc or Ctrl-C raises Cancelled.