Class: OSPFv2::Input
- Includes:
- Observable
- Defined in:
- lib/infra/ospf_io.rb
Instance Attribute Summary collapse
-
#sock ⇒ Object
readonly
Returns the value of attribute sock.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(sock, neighbor, ev_handler) ⇒ Input
constructor
A new instance of Input.
- #our_address ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(sock, neighbor, ev_handler) ⇒ Input
Returns a new instance of Input.
34 35 36 37 38 39 40 |
# File 'lib/infra/ospf_io.rb', line 34 def initialize(sock, neighbor, ev_handler) super() @sock=sock @neighbor=neighbor add_observer(ev_handler) @continue=true end |
Instance Attribute Details
#sock ⇒ Object (readonly)
Returns the value of attribute sock.
32 33 34 |
# File 'lib/infra/ospf_io.rb', line 32 def sock @sock end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
42 43 44 |
# File 'lib/infra/ospf_io.rb', line 42 def thread @thread end |
Instance Method Details
#our_address ⇒ Object
44 45 46 |
# File 'lib/infra/ospf_io.rb', line 44 def our_address @neighbor.address end |
#start ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/infra/ospf_io.rb', line 54 def start @thread = Thread.new(@sock) do |s| Thread.current['name'] = self.class.to_s begin while @continue from, port, data = s.recv hdr = header(data) if hdr[:ip_proto] == 89 and data[20] == 2 if from != our_address changed and notify_observers(:ev_recv, data, from, port) # * @sock.recv .... end end end rescue Exception => e p e end end end |
#stop ⇒ Object
48 49 50 51 52 |
# File 'lib/infra/ospf_io.rb', line 48 def stop @thread.exit @thread.join rescue end |