Class: Bro::Connection
- Inherits:
-
Object
- Object
- Bro::Connection
- Includes:
- Broccoli
- Defined in:
- lib/Bro/connection.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
- #event_handler(event, &callback) ⇒ Object (also: #event_handler_for)
-
#initialize(hp, flags = nil) ⇒ Connection
constructor
A new instance of Connection.
- #process_input ⇒ Object
- #queue_flush ⇒ Object
- #queue_length ⇒ Object
- #queue_length_max ⇒ Object
- #send(event) ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(hp, flags = nil) ⇒ Connection
Returns a new instance of Connection.
14 15 16 17 18 19 |
# File 'lib/Bro/connection.rb', line 14 def initialize(hp, flags=nil) flags ||= (BRO_CFLAG_RECONNECT | BRO_CFLAG_ALWAYS_QUEUE) @bc = bro_conn_new_str(hp, flags) @io_object = nil @event_blocks = [] end |
Instance Method Details
#connect ⇒ Object
25 26 27 |
# File 'lib/Bro/connection.rb', line 25 def connect bro_conn_connect(@bc) end |
#connected? ⇒ Boolean
29 30 31 |
# File 'lib/Bro/connection.rb', line 29 def connected? bro_conn_alive?(@bc) end |
#disconnect ⇒ Object
21 22 23 |
# File 'lib/Bro/connection.rb', line 21 def disconnect bro_conn_delete(@bc) end |
#event_handler(event, &callback) ⇒ Object Also known as: event_handler_for
70 71 72 73 74 |
# File 'lib/Bro/connection.rb', line 70 def event_handler(event, &callback) bro_event_registry_add_compact(@bc, event, callback) # Re-request all events if we're already connected. bro_event_registry_request(@bc) if connected? end |
#process_input ⇒ Object
33 34 35 |
# File 'lib/Bro/connection.rb', line 33 def process_input bro_conn_process_input(@bc) end |
#queue_flush ⇒ Object
45 46 47 |
# File 'lib/Bro/connection.rb', line 45 def queue_flush bro_event_queue_flush(@bc) end |
#queue_length ⇒ Object
37 38 39 |
# File 'lib/Bro/connection.rb', line 37 def queue_length bro_event_queue_length(@bc) end |
#queue_length_max ⇒ Object
41 42 43 |
# File 'lib/Bro/connection.rb', line 41 def queue_length_max bro_event_queue_length_max(@bc) end |
#send(event) ⇒ Object
49 50 51 52 |
# File 'lib/Bro/connection.rb', line 49 def send(event) # .ev is the real event pointer bro_event_send(@bc, event.ev) end |
#wait ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/Bro/connection.rb', line 54 def wait unless @io_object fd = bro_conn_get_fd(@bc) return false if fd < 0 @io_object = IO.new(fd) @io_object.sync = true # don't buffer end # block until there is data if @io_object.closed? puts "ERROR: connection lost!" exit -1 else IO.select([@io_object]) end end |