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.
37 38 39 40 41 42 43 |
# File 'lib/infra/ospf_io.rb', line 37 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.
35 36 37 |
# File 'lib/infra/ospf_io.rb', line 35 def sock @sock end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
45 46 47 |
# File 'lib/infra/ospf_io.rb', line 45 def thread @thread end |
Instance Method Details
#our_address ⇒ Object
47 48 49 |
# File 'lib/infra/ospf_io.rb', line 47 def our_address @neighbor.address end |
#start ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/infra/ospf_io.rb', line 57 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 or data[20] == "\x02") 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
51 52 53 54 55 |
# File 'lib/infra/ospf_io.rb', line 51 def stop @thread.exit @thread.join rescue end |