pulse-meter 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,17 @@
1
1
  require 'socket'
2
+ require 'fcntl'
2
3
 
3
4
  module PulseMeter
4
5
  module CommandAggregator
5
6
  class UDP
6
7
 
7
- def initialize(host, port)
8
- @host, @port = host, port
8
+ def initialize(servers = [])
9
+ raise ArgumentError, "No servers specified" if servers.empty?
10
+ @servers = servers
9
11
  @buffer = []
10
12
  @in_multi = false
13
+ @sock = UDPSocket.new
14
+ @sock.fcntl(Fcntl::F_SETFL, @sock.fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK)
11
15
  end
12
16
 
13
17
  def multi
@@ -27,9 +31,7 @@ module PulseMeter
27
31
 
28
32
  def send_buffer
29
33
  data = @buffer.to_json
30
- sock = UDPSocket.new
31
- sock.send(data, 0, @host, @port)
32
- sock.close
34
+ @sock.send(data, 0, *@servers.sample)
33
35
  rescue StandardError
34
36
  PulseMeter.error "error sending data: #{e}, #{e.backtrace.join("\n")}"
35
37
  ensure
@@ -1,3 +1,3 @@
1
1
  module PulseMeter
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -6,8 +6,8 @@ describe PulseMeter::CommandAggregator::UDP do
6
6
  let(:udp_sock){mock(:socket)}
7
7
  before do
8
8
  UDPSocket.stub!(:new).and_return(udp_sock)
9
- udp_sock.stub!(:close).and_return(nil)
10
- @ca = described_class.new(host, port)
9
+ udp_sock.stub!(:fcntl).and_return(nil)
10
+ @ca = described_class.new([[host, port]])
11
11
  end
12
12
 
13
13
  describe "#multi" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pulse-meter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: