arachni-reactor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8f90922fd68d3df405cf0aa7537924db3f3c118
4
- data.tar.gz: 5bd9e5042618276a83909b43879651d60f8e0538
3
+ metadata.gz: 6c421c44ae454d55db1adc102b4c9d0819375ff0
4
+ data.tar.gz: b05b9f1ddf6048d8e0df60684b738e879628e48c
5
5
  SHA512:
6
- metadata.gz: ff7c11326a30b31030b95ac93cd7ee3e5c37ab6f7097bb6f9a4829354b13bc683d484e8243bb9d14e88b8248bd69481a9a43ac01d475a708e61199595ec4632b
7
- data.tar.gz: f1563d0bafe856937029267327fa8c049b05a56122e8fa8dd5c1fd0b45bb7e9784f250eb8dfd4d6438d8b866cd402de4340b9382d5a304c204fd54552c4a389c
6
+ metadata.gz: 83ba17f94bed4e8d8d8b6125ed06288051a3bc59bd34733f355db80757e01f65d7074459670c1cedb95ffc2c0242dfc8219ea4988199f5fb0c63139152e6182c
7
+ data.tar.gz: e7a6690fa5d3c8f496e19a34e6d7d942548dc5dbb3ef62905a1e2c7a29c9fbd5b3923527ad2cf60c3ed707666ec6854577f6e135ef30eabe87ca9d3db50b18ec
@@ -1,5 +1,12 @@
1
1
  # ChangeLog
2
2
 
3
+ ## Version 0.1.1
4
+
5
+ - `Connection`
6
+ - `#_write` -- Use `String#byteslice` instead of `String#slice` and
7
+ `String#bytesize` instead of `String#size`.
8
+ - `Error.translate` -- Translate `Errno::ECONNABORTED` as `Error::Reset`.
9
+
3
10
  ## Version 0.1.0
4
11
 
5
12
  - Cleaned up connection handling structure for JRuby support.
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # License
2
2
 
3
- Copyright (C) 2014, Tasos Laskos <tasos.laskos@gmail.com>
3
+ Copyright (C) 2014-2016, Tasos Laskos <tasos.laskos@gmail.com>
4
4
  All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without modification,
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <table>
4
4
  <tr>
5
5
  <th>Version</th>
6
- <td>0.1.0</td>
6
+ <td>0.1.1</td>
7
7
  </tr>
8
8
  <tr>
9
9
  <th>Github page</th>
@@ -23,7 +23,7 @@
23
23
  </tr>
24
24
  <tr>
25
25
  <th>Copyright</th>
26
- <td>2014</td>
26
+ <td>2014-2016</td>
27
27
  </tr>
28
28
  <tr>
29
29
  <th>License</th>
@@ -668,9 +668,11 @@ class Reactor
668
668
  # So force a read for SSL sockets to cover all our bases.
669
669
  #
670
670
  # This is apparent especially on JRuby.
671
- (readables - selected_sockets[0]).each do |socket|
672
- next if !socket.is_a?( OpenSSL::SSL::SSLSocket )
673
- selected_sockets[0] << socket
671
+ if readables.size != selected_sockets[0].size
672
+ (readables - selected_sockets[0]).each do |socket|
673
+ next if !socket.is_a?( OpenSSL::SSL::SSLSocket )
674
+ selected_sockets[0] << socket
675
+ end
674
676
  end
675
677
 
676
678
  if selected_sockets[0].empty? && selected_sockets[1].empty? &&
@@ -41,17 +41,21 @@ class Connection
41
41
  # `true` when using a UNIX-domain socket, `nil` if no {#socket} is
42
42
  # available, `false` otherwise.
43
43
  def unix?
44
+ return @is_unix if !@is_unix.nil?
44
45
  return if !to_io
45
46
  return false if !Arachni::Reactor.supports_unix_sockets?
46
- to_io.is_a?( UNIXServer ) || to_io.is_a?( UNIXSocket )
47
+
48
+ @is_unix = to_io.is_a?( UNIXServer ) || to_io.is_a?( UNIXSocket )
47
49
  end
48
50
 
49
51
  # @return [Bool]
50
52
  # `true` when using an Internet socket, `nil` if no {#socket} is
51
53
  # available, `false` otherwise.
52
54
  def inet?
55
+ return @is_inet if !@is_inet.nil?
53
56
  return if !to_io
54
- to_io.is_a?( TCPServer ) || to_io.is_a?( TCPSocket ) || to_io.is_a?( Socket )
57
+
58
+ @is_inet = to_io.is_a?( TCPServer ) || to_io.is_a?( TCPSocket ) || to_io.is_a?( Socket )
55
59
  end
56
60
 
57
61
  # @return [IO, nil]
@@ -64,8 +68,10 @@ class Connection
64
68
  # @return [Bool]
65
69
  # `true` if the connection is a server listener.
66
70
  def listener?
71
+ return @is_listener if !@is_listener.nil?
67
72
  return if !to_io
68
- to_io.is_a?( TCPServer ) || (unix? && to_io.is_a?( UNIXServer ))
73
+
74
+ @is_listener = to_io.is_a?( TCPServer ) || (unix? && to_io.is_a?( UNIXServer ))
69
75
  end
70
76
 
71
77
  # @note The data will be buffered and sent in future {Reactor} ticks.
@@ -228,7 +234,7 @@ class Connection
228
234
  socket.connect_nonblock( Socket.sockaddr_in( @port, @host ) )
229
235
  end
230
236
  # Already connected. :)
231
- rescue Errno::EISCONN
237
+ rescue Errno::EISCONN, Errno::EALREADY
232
238
  end
233
239
 
234
240
  @connected = true
@@ -277,7 +283,7 @@ class Connection
277
283
  def _write
278
284
  return _connect if !connected?
279
285
 
280
- chunk = write_buffer.slice( 0, BLOCK_SIZE )
286
+ chunk = write_buffer.byteslice( 0, BLOCK_SIZE )
281
287
  total_written = 0
282
288
 
283
289
  begin
@@ -285,13 +291,13 @@ class Connection
285
291
  # Send out the chunk, **all** of it, or at least try to.
286
292
  loop do
287
293
  total_written += written = @socket.write_nonblock( chunk )
288
- write_buffer.slice!( 0, written )
294
+ @write_buffer = @write_buffer.byteslice( written..-1 )
289
295
 
290
296
  # Call #on_write every time any of the buffer is consumed.
291
297
  on_write
292
298
 
293
- break if written == chunk.size
294
- chunk.slice!( 0, written )
299
+ break if written == chunk.bytesize
300
+ chunk = chunk.byteslice( written..-1 )
295
301
  end
296
302
  end
297
303
 
@@ -35,7 +35,7 @@ class Error < Arachni::Reactor::Error
35
35
  # non-existent server.
36
36
  Errno::EADDRINUSE => e
37
37
  raise_with_proper_backtrace( e, Refused )
38
- rescue Errno::ECONNRESET => e
38
+ rescue Errno::ECONNRESET, Errno::ECONNABORTED => e
39
39
  raise_with_proper_backtrace( e, Reset )
40
40
  rescue Errno::EACCES => e
41
41
  raise_with_proper_backtrace( e, Permission )
@@ -9,7 +9,7 @@
9
9
  module Arachni
10
10
  class Reactor
11
11
 
12
- VERSION = '0.1.0'
12
+ VERSION = '0.1.1'
13
13
 
14
14
  end
15
15
  end
@@ -35,7 +35,9 @@ describe Arachni::Reactor::Tasks::Delayed do
35
35
  time = Time.now
36
36
  task.call while called < 1
37
37
 
38
- (Time.now - time).round(2).should == 0.25
38
+ elapsed = (Time.now - time).round(2)
39
+ elapsed.should >= 0.25
40
+ elapsed.should < 0.30
39
41
  end
40
42
 
41
43
  it 'calls #done' do
@@ -33,7 +33,9 @@ describe Arachni::Reactor::Tasks::Periodic do
33
33
  time = Time.now
34
34
  task.call while called < 5
35
35
 
36
- (Time.now - time).round(2).should == 1.25
36
+ elapsed = (Time.now - time).round(2)
37
+ elapsed.should >= 1.25
38
+ elapsed.should < 1.35
37
39
  end
38
40
  end
39
41
 
@@ -77,7 +77,7 @@ class Servers
77
77
  return if !server_info[:pid]
78
78
 
79
79
  begin
80
- Process.kill( Gem.win_platform? ? 'QUIT' : 'KILL', server_info[:pid] ) while sleep 0.1
80
+ Process.kill( 'KILL', server_info[:pid] ) while sleep 0.1
81
81
  rescue Errno::ESRCH
82
82
  server_info.delete(:pid)
83
83
 
@@ -816,6 +816,9 @@ shared_examples_for 'Arachni::Reactor' do
816
816
  subject.listen( host, port, echo_server_handler, *options )
817
817
 
818
818
  @socket = tcp_writer.call( host, port, data )
819
+
820
+ sleep 5
821
+
819
822
  subject.connections.values.first.initialization_args.should == options
820
823
  end
821
824
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arachni-reactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-21 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Arachni::Reactor is a simple, lightweight, pure-Ruby implementation of the Reactor
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.4.5
101
+ rubygems_version: 2.5.1
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: A pure-Ruby implementation of the Reactor pattern.