ruby_ami 1.2.6 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -12,3 +12,4 @@ spec/reports
12
12
  features/reports
13
13
  vendor
14
14
  *.swp
15
+ .rbx/*
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # [develop](https://github.com/adhearsion/ruby_ami)
2
2
 
3
+ # [1.3.0](https://github.com/adhearsion/ruby_ami/compare/v1.2.6...v1.3.0) - [2013-01-23](https://rubygems.org/gems/ruby_ami/versions/1.3.0)
4
+ * Feature: Added timeout feature to client connection process. Currently does not work on Rubinius due to https://github.com/rubinius/rubinius/issues/2127
5
+
3
6
  # [1.2.6](https://github.com/adhearsion/ruby_ami/compare/v1.2.5...v1.2.6) - [2012-12-26](https://rubygems.org/gems/ruby_ami/versions/1.2.6)
4
7
  * Bugfix: JRuby and rbx compatability
5
8
 
data/README.md CHANGED
@@ -18,7 +18,8 @@ client = Client.new :username => 'test',
18
18
  :port => 5038,
19
19
  :event_handler => lambda { |e| handle_event e },
20
20
  :logger => Logger.new(STDOUT),
21
- :log_level => Logger::DEBUG
21
+ :log_level => Logger::DEBUG,
22
+ :timeout => 10
22
23
 
23
24
  def handle_event(event)
24
25
  case event.name
@@ -10,6 +10,10 @@ module RubyAMI
10
10
  @event_handler = @options[:event_handler]
11
11
  @state = :stopped
12
12
 
13
+ if RubyAMI.rbx?
14
+ logger.warn 'The "timeout" parameter is not supported when using Rubinius'
15
+ end
16
+
13
17
  stop_writing_actions
14
18
 
15
19
  @pending_actions = {}
@@ -181,7 +185,7 @@ module RubyAMI
181
185
  end
182
186
 
183
187
  def new_stream(callback)
184
- Stream.new @options[:host], @options[:port], callback, logger
188
+ Stream.new @options[:host], @options[:port], callback, logger, @options[:timeout]
185
189
  end
186
190
 
187
191
  def logger
@@ -16,9 +16,9 @@ module RubyAMI
16
16
 
17
17
  attr_reader :logger
18
18
 
19
- def initialize(host, port, event_callback, logger = Logger)
19
+ def initialize(host, port, event_callback, logger = Logger, timeout = 0)
20
20
  super()
21
- @host, @port, @event_callback, @logger = host, port, event_callback, logger
21
+ @host, @port, @event_callback, @logger, @timeout = host, port, event_callback, logger, timeout
22
22
  logger.debug "Starting up..."
23
23
  @lexer = Lexer.new self
24
24
  end
@@ -28,7 +28,9 @@ module RubyAMI
28
28
  end
29
29
 
30
30
  def run
31
- @socket = TCPSocket.from_ruby_socket ::TCPSocket.new(@host, @port)
31
+ Timeout::timeout(@timeout) do
32
+ @socket = TCPSocket.from_ruby_socket ::TCPSocket.new(@host, @port)
33
+ end
32
34
  post_init
33
35
  loop { receive_data @socket.readpartial(4096) }
34
36
  rescue Errno::ECONNREFUSED, SocketError => e
@@ -37,6 +39,9 @@ module RubyAMI
37
39
  rescue EOFError
38
40
  logger.info "Client socket closed!"
39
41
  current_actor.terminate!
42
+ rescue Timeout::Error
43
+ logger.error "Timeout exceeded while trying to connect."
44
+ current_actor.terminate!
40
45
  end
41
46
 
42
47
  def post_init
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module RubyAMI
3
- VERSION = "1.2.6"
3
+ VERSION = "1.3.0"
4
4
  end
data/lib/ruby_ami.rb CHANGED
@@ -14,6 +14,10 @@ module RubyAMI
14
14
  def self.new_uuid
15
15
  SecureRandom.uuid
16
16
  end
17
+
18
+ def self.rbx?
19
+ RbConfig::CONFIG['RUBY_INSTALL_NAME'] == 'rbx'
20
+ end
17
21
  end
18
22
 
19
23
  %w{
@@ -25,6 +25,23 @@ module RubyAMI
25
25
 
26
26
  its(:streams) { should == [] }
27
27
 
28
+ it 'should return when the timeout option is specified and reached' do
29
+ options[:timeout] = 2
30
+ options[:host] = '192.0.2.1' # unreachable IP that will generally cause a timeout (RFC 5737)
31
+
32
+ start_time = Time.now
33
+ subject.start
34
+ duration = Time.now - start_time
35
+
36
+ if RubyAMI.rbx?
37
+ pending 'waiting for resolution to Rubinius bug (https://github.com/rubinius/rubinius/issues/2127)' do
38
+ duration.should be_between(options[:timeout], options[:timeout] + 1)
39
+ end
40
+ else
41
+ duration.should be_between(options[:timeout], options[:timeout] + 1)
42
+ end
43
+ end
44
+
28
45
  describe 'starting up' do
29
46
  before do
30
47
  ms = MockServer.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_ami
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-26 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid-io
@@ -283,7 +283,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
283
283
  version: '0'
284
284
  segments:
285
285
  - 0
286
- hash: -1351275234021844884
286
+ hash: 3069284135143660442
287
287
  required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  none: false
289
289
  requirements:
@@ -292,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
292
  version: '0'
293
293
  segments:
294
294
  - 0
295
- hash: -1351275234021844884
295
+ hash: 3069284135143660442
296
296
  requirements: []
297
297
  rubyforge_project: ruby_ami
298
298
  rubygems_version: 1.8.24