random-port 0.7.3 → 0.7.4

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
  SHA256:
3
- metadata.gz: 627f7f283d6d1958380c9794dd78a50b7068144afa5e7b6f988d8cca325cf114
4
- data.tar.gz: 4559900eed96735698944d63366666130fbb729b1a12a26d79a9e77eb5085bec
3
+ metadata.gz: 97daaf8ddcb40b28c9702c20272747d85619de8b19301f05a34918c6dd275cca
4
+ data.tar.gz: 48a06545628a4bfb4c3ee8b59e1880d83cd22cacc5fa22a893717b70225f08a5
5
5
  SHA512:
6
- metadata.gz: e1bea15f564c1b5f9e4bc292b71501aa799b6b674337b1c9c504cbd7edee6bbd508c4beb4fe3648fdc83a184d3924ca4a595b253b383f9d2cb7d213ee518ae1c
7
- data.tar.gz: db5b1ee1490292eaf644eb68567d1289354a355c6a2c768037005db2d44111bc232f120358ffc231964579b005315269e0927de96f547c4ad012a87c84220b65
6
+ metadata.gz: da44606055d80695de6baea9ef514b98d5b5d0cf82bac7276981edef778f2aabb7d2532d722b576eabffd2d4a58e7d21a8ee8effbb48f7d2c86e1b02dbd9ffed
7
+ data.tar.gz: 49c67ec4a38bdcf60cf12d7d53078ddbf70370899cd5da8c03cd7ce82a46750ba79bf35242d2b6cf32ab31742c4ebea0bec473ee95448e6b3692c21ec6965393
@@ -21,7 +21,11 @@
21
21
  name: copyrights
22
22
  'on':
23
23
  push:
24
+ branches:
25
+ - master
24
26
  pull_request:
27
+ branches:
28
+ - master
25
29
  jobs:
26
30
  copyrights:
27
31
  runs-on: ubuntu-24.04
@@ -19,9 +19,13 @@
19
19
  # SOFTWARE.
20
20
  ---
21
21
  name: xcop
22
- on:
22
+ 'on':
23
23
  push:
24
+ branches:
25
+ - master
24
26
  pull_request:
27
+ branches:
28
+ - master
25
29
  jobs:
26
30
  xcop:
27
31
  runs-on: ubuntu-24.04
@@ -96,25 +96,14 @@ class RandomPort::Pool
96
96
  "for #{total} port(s), after #{attempt} attempts in #{start.ago}"
97
97
  end
98
98
  attempt += 1
99
- opts = safe do
100
- next if @ports.count + total > @limit
101
- opts = Array.new(0, total)
102
- begin
103
- (0..(total - 1)).each do |i|
104
- opts[i] = take(i.zero? ? @next : opts[i - 1] + 1)
105
- end
106
- rescue Errno::EADDRINUSE, SocketError
107
- next
108
- end
109
- next if opts.any? { |p| @ports.include?(p) }
110
- d = total * (total - 1) / 2
111
- next unless opts.inject(&:+) - (total * opts.min) == d
112
- @ports += opts
113
- opts
99
+ opts = safe { group(total) }
100
+ if opts.nil?
101
+ @next += 1
102
+ else
103
+ @next = opts.max + 1
114
104
  end
115
- next if opts.nil?
116
- @next = opts.max + 1
117
105
  @next = 0 if @next > 65_535
106
+ next if opts.nil?
118
107
  opts = opts[0] if total == 1
119
108
  return opts unless block_given?
120
109
  begin
@@ -126,6 +115,8 @@ class RandomPort::Pool
126
115
  end
127
116
 
128
117
  # Return it/them back to the pool.
118
+ # @param [Integer] port TCP port number to release
119
+ # @return nil
129
120
  def release(port)
130
121
  safe do
131
122
  if port.is_a?(Array)
@@ -138,6 +129,27 @@ class RandomPort::Pool
138
129
 
139
130
  private
140
131
 
132
+ # Take a group of ports, if possible.
133
+ # @param [Integer] total How many ports to take
134
+ # @return [Array<Integer>|nil] Ports found or NIL if impossible now
135
+ def group(total)
136
+ return if @ports.count + total > @limit
137
+ opts = Array.new(0, total)
138
+ begin
139
+ (0..(total - 1)).each do |i|
140
+ port = i.zero? ? @next : opts[i - 1] + 1
141
+ opts[i] = take(port)
142
+ end
143
+ rescue Errno::EADDRINUSE, SocketError
144
+ return
145
+ end
146
+ return if opts.any? { |p| @ports.include?(p) }
147
+ d = total * (total - 1) / 2
148
+ return unless opts.inject(&:+) - (total * opts.min) == d
149
+ @ports += opts
150
+ opts
151
+ end
152
+
141
153
  # Find one possible TCP port.
142
154
  # @param [Integer] opt Suggested port number
143
155
  # @return [Integer] Port found
data/random-port.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
28
28
  s.required_ruby_version = '>=2.3'
29
29
  s.name = 'random-port'
30
- s.version = '0.7.3'
30
+ s.version = '0.7.4'
31
31
  s.license = 'MIT'
32
32
  s.summary = 'Random TCP port'
33
33
  s.description = 'Reserves a random TCP port'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random-port
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko