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(
|
8
|
-
|
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
|
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
|
data/lib/pulse-meter/version.rb
CHANGED
@@ -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!(:
|
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
|