random-port 0.7.2 → 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: 7955c6c026633ceb489c05357e4d0383aca879252680a87053339682e014fe0f
4
- data.tar.gz: ab010bcab3569cce98f608c38dfe23929ff5d8c94bba8a15e46c1e486aef71d0
3
+ metadata.gz: 97daaf8ddcb40b28c9702c20272747d85619de8b19301f05a34918c6dd275cca
4
+ data.tar.gz: 48a06545628a4bfb4c3ee8b59e1880d83cd22cacc5fa22a893717b70225f08a5
5
5
  SHA512:
6
- metadata.gz: 5861bf9d24fbb7c4cdc9ca9393736c0d65ee3e30f207a715ac0f7366f8b13ebaf442e5ebff10ae1787515bceab7f257aea44b9592a09c7f9f27d57015805ac2b
7
- data.tar.gz: de319e8a9c70bc72a98ea456297079c732a41a3deac2b9c943065a601446ff2f828cfc7bb1a0a25f24327ed72fd6605129021aa06e23defe89095a7257bfe0a8
6
+ metadata.gz: da44606055d80695de6baea9ef514b98d5b5d0cf82bac7276981edef778f2aabb7d2532d722b576eabffd2d4a58e7d21a8ee8effbb48f7d2c86e1b02dbd9ffed
7
+ data.tar.gz: 49c67ec4a38bdcf60cf12d7d53078ddbf70370899cd5da8c03cd7ce82a46750ba79bf35242d2b6cf32ab31742c4ebea0bec473ee95448e6b3692c21ec6965393
@@ -30,7 +30,7 @@ jobs:
30
30
  - uses: actions/checkout@v4
31
31
  - uses: ruby/setup-ruby@v1
32
32
  with:
33
- ruby-version: 2.7
33
+ ruby-version: 3.3
34
34
  - run: bundle update
35
35
  - run: bundle exec rake
36
36
  - uses: codecov/codecov-action@v5
@@ -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
@@ -31,8 +31,8 @@ jobs:
31
31
  name: test
32
32
  strategy:
33
33
  matrix:
34
- os: [ubuntu-24.04, macos-15]
35
- ruby: [2.7, 3.3]
34
+ os: [ubuntu-24.04, macos-15, windows-2022]
35
+ ruby: [3.3]
36
36
  runs-on: ${{ matrix.os }}
37
37
  steps:
38
38
  - uses: actions/checkout@v4
@@ -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
@@ -92,28 +92,18 @@ class RandomPort::Pool
92
92
  raise \
93
93
  Timeout,
94
94
  "Can't find a place in the pool of #{@limit} ports " \
95
+ "(#{@ports.size} already occupied) " \
95
96
  "for #{total} port(s), after #{attempt} attempts in #{start.ago}"
96
97
  end
97
98
  attempt += 1
98
- opts = safe do
99
- next if @ports.count + total > @limit
100
- opts = Array.new(0, total)
101
- begin
102
- (0..(total - 1)).each do |i|
103
- opts[i] = take(i.zero? ? @next : opts[i - 1] + 1)
104
- end
105
- rescue Errno::EADDRINUSE, SocketError
106
- next
107
- end
108
- next if opts.any? { |p| @ports.include?(p) }
109
- d = total * (total - 1) / 2
110
- next unless opts.inject(&:+) - (total * opts.min) == d
111
- @ports += opts
112
- opts
99
+ opts = safe { group(total) }
100
+ if opts.nil?
101
+ @next += 1
102
+ else
103
+ @next = opts.max + 1
113
104
  end
114
- next if opts.nil?
115
- @next = opts.max + 1
116
105
  @next = 0 if @next > 65_535
106
+ next if opts.nil?
117
107
  opts = opts[0] if total == 1
118
108
  return opts unless block_given?
119
109
  begin
@@ -125,6 +115,8 @@ class RandomPort::Pool
125
115
  end
126
116
 
127
117
  # Return it/them back to the pool.
118
+ # @param [Integer] port TCP port number to release
119
+ # @return nil
128
120
  def release(port)
129
121
  safe do
130
122
  if port.is_a?(Array)
@@ -137,6 +129,27 @@ class RandomPort::Pool
137
129
 
138
130
  private
139
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
+
140
153
  # Find one possible TCP port.
141
154
  # @param [Integer] opt Suggested port number
142
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.2'
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.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko