Class: Rex::IO::RelayManager
- Inherits:
-
Object
- Object
- Rex::IO::RelayManager
- Defined in:
- lib/rex/io/relay_manager.rb
Overview
An IO RelayManager which will read data from a socket and write it to a sink using a background thread.
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
-
.io_write_all(io, data) ⇒ Object
Write all data to the specified IO.
Instance Method Summary collapse
-
#add_relay(sock, sink: nil, name: nil, on_exit: nil) ⇒ Object
Add a IO relay to the manager.
-
#initialize ⇒ RelayManager
constructor
A new instance of RelayManager.
Constructor Details
#initialize ⇒ RelayManager
Returns a new instance of RelayManager.
11 12 13 14 |
# File 'lib/rex/io/relay_manager.rb', line 11 def initialize @thread = nil @scheduler = FiberScheduler.new end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
9 10 11 |
# File 'lib/rex/io/relay_manager.rb', line 9 def thread @thread end |
Class Method Details
.io_write_all(io, data) ⇒ Object
Write all data to the specified IO. This is intended to be used in scenarios where partial writes are possible but not desirable.
42 43 44 45 46 47 48 49 |
# File 'lib/rex/io/relay_manager.rb', line 42 def self.io_write_all(io, data) offset = 0 while offset < data.bytesize written = io.write(data.byteslice(offset..-1)) offset += written end data.bytesize end |
Instance Method Details
#add_relay(sock, sink: nil, name: nil, on_exit: nil) ⇒ Object
Add a IO relay to the manager. This will start relaying data from the source socket to the destination sink immediately. An optional “on_exit” callback can be provided which will be called when the socket is closed.
28 29 30 31 32 33 34 |
# File 'lib/rex/io/relay_manager.rb', line 28 def add_relay(sock, sink: nil, name: nil, on_exit: nil) @scheduler.schedule_fiber do relay_fiber(sock, sink, name, on_exit: on_exit) end start unless running? end |