Class: RSwim::Integration::UDP::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/rswim/integration/udp/sender.rb

Instance Method Summary collapse

Constructor Details

#initialize(port, out_q) ⇒ Sender

Returns a new instance of Sender.



7
8
9
10
11
# File 'lib/rswim/integration/udp/sender.rb', line 7

def initialize(port, out_q)
  @out_q = out_q
  @port = port
  @out_s = UDPSocket.new
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rswim/integration/udp/sender.rb', line 13

def run
  Async do
    loop do
      wire_messages = @out_q.pop
      wire_messages.each do |(host, wire_message)|
        logger.debug "about to send message to #{host} on port #{@port}"
        Fiber.schedule do
          @out_s.send(wire_message, 0, host, @port)
        rescue StandardError => e
          logger.debug("Error while sending: #{e}")
        end
      end
    end
  end
end