Class: Mu::Pcap::IOWrapper
- Inherits:
-
Object
- Object
- Mu::Pcap::IOWrapper
- Defined in:
- lib/mu/pcap/io_wrapper.rb
Constant Summary collapse
- MAX_RECEIVE_SIZE =
Impose upper limit to protect against memory exhaustion.
1048576
Instance Attribute Summary collapse
-
#ios ⇒ Object
readonly
Returns the value of attribute ios.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#unread ⇒ Object
readonly
Returns the value of attribute unread.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(ios, reader) ⇒ IOWrapper
constructor
A new instance of IOWrapper.
- #open ⇒ Object
- #open? ⇒ Boolean
-
#read ⇒ Object
Returns next higher level protocol message.
-
#record_write(bytes) ⇒ Object
Parser may need to see requests to understand responses.
- #write(bytes, *args) ⇒ Object
- #write_to(bytes, *args) ⇒ Object
Constructor Details
#initialize(ios, reader) ⇒ IOWrapper
Returns a new instance of IOWrapper.
12 13 14 15 16 17 18 19 |
# File 'lib/mu/pcap/io_wrapper.rb', line 12 def initialize ios, reader @ios = ios @reader = reader # parse state for reader @state = {} # read off of underlying io but not yet processed by @reader @unread = "" end |
Instance Attribute Details
#ios ⇒ Object (readonly)
Returns the value of attribute ios.
10 11 12 |
# File 'lib/mu/pcap/io_wrapper.rb', line 10 def ios @ios end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
10 11 12 |
# File 'lib/mu/pcap/io_wrapper.rb', line 10 def state @state end |
#unread ⇒ Object (readonly)
Returns the value of attribute unread.
10 11 12 |
# File 'lib/mu/pcap/io_wrapper.rb', line 10 def unread @unread end |
Instance Method Details
#close ⇒ Object
70 71 72 |
# File 'lib/mu/pcap/io_wrapper.rb', line 70 def close @ios.close end |
#open ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/mu/pcap/io_wrapper.rb', line 58 def open if block_given? @ios.open { yield } else @ios.open end end |
#open? ⇒ Boolean
66 67 68 |
# File 'lib/mu/pcap/io_wrapper.rb', line 66 def open? @ios.open? end |
#read ⇒ Object
Returns next higher level protocol message.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mu/pcap/io_wrapper.rb', line 25 def read until = @reader.(@unread, @state) bytes = @ios.read if bytes and not bytes.empty? @unread << bytes else return nil end if @unread.size > MAX_RECEIVE_SIZE raise "Maximum message size (#{MAX_RECEIVE_SIZE}) exceeded" end end return end |
#record_write(bytes) ⇒ Object
Parser may need to see requests to understand responses.
42 43 44 |
# File 'lib/mu/pcap/io_wrapper.rb', line 42 def record_write bytes @reader.record_write bytes, @state end |
#write(bytes, *args) ⇒ Object
46 47 48 49 50 |
# File 'lib/mu/pcap/io_wrapper.rb', line 46 def write bytes, *args w = @ios.write bytes, *args record_write bytes w end |
#write_to(bytes, *args) ⇒ Object
52 53 54 55 56 |
# File 'lib/mu/pcap/io_wrapper.rb', line 52 def write_to bytes, *args w = @ios.write_to bytes, *args record_write bytes w end |