Class: Pants::Readers::UDPReaderConnection
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Pants::Readers::UDPReaderConnection
- Includes:
- LogSwitch::Mixin, NetworkHelpers
- Defined in:
- lib/pants/readers/udp_reader.rb
Overview
This is the EventMachine connection that reads on the source IP and UDP port. It places all read data onto the data channel. Allows for unicast or multicast addresses; it’ll detect which to use from the IP you pass in.
Instance Method Summary collapse
-
#initialize(write_to_channel, starter_callback) ⇒ UDPReaderConnection
constructor
A new instance of UDPReaderConnection.
- #post_init ⇒ Object
-
#receive_data(data) ⇒ Object
Reads the data and writes it to the data channel.
Constructor Details
#initialize(write_to_channel, starter_callback) ⇒ UDPReaderConnection
Returns a new instance of UDPReaderConnection.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pants/readers/udp_reader.rb', line 21 def initialize(write_to_channel, starter_callback) @write_to_channel = write_to_channel @starter_callback = starter_callback port, ip = Socket.unpack_sockaddr_in(get_sockname) if Addrinfo.ip(ip).ipv4_multicast? || Addrinfo.ip(ip).ipv6_multicast? log "Got a multicast address: #{ip}:#{port}" setup_multicast_socket(ip) else log "Got a unicast address: #{ip}:#{port}" end end |
Instance Method Details
#post_init ⇒ Object
34 35 36 |
# File 'lib/pants/readers/udp_reader.rb', line 34 def post_init @starter_callback.call end |
#receive_data(data) ⇒ Object
Reads the data and writes it to the data channel.
41 42 43 |
# File 'lib/pants/readers/udp_reader.rb', line 41 def receive_data(data) @write_to_channel << data end |