random-port 0.2.0 → 0.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.
- checksums.yaml +5 -5
- data/README.md +15 -1
- data/lib/random-port/pool.rb +14 -16
- data/random-port.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1dbc9a31f4b53484b240f4f2bb37c7f1ed9208bc1e5e31b09df8c95c9aa909d1
|
4
|
+
data.tar.gz: 9d6f1d3e5a912ffa03ac3a168bc47d1492775435276a709a33d918b5b103ec00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d382bafa4db3b722d8ebefda93d5c5460a3e61581bab49646cc804841f4f7edafb9203c2006557c16ef6aa6b6111ed9db011cd68f3a104b1a165fc8834e31f40
|
7
|
+
data.tar.gz: d1318acea077ce7df07d2d514c6b9f676581c8d2b69ddb43337cc148567cdeb16f7c1584559723833319053ae287dbba6ca228a9d236493d6bd52b9433441d3d
|
data/README.md
CHANGED
@@ -46,7 +46,21 @@ RandomPort::Pool::SINGLETON.acquire do |port|
|
|
46
46
|
end
|
47
47
|
```
|
48
48
|
|
49
|
-
The pool is thread-safe.
|
49
|
+
The pool is _not_ thread-safe.
|
50
|
+
|
51
|
+
# How to contribute
|
52
|
+
|
53
|
+
Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
54
|
+
Make sure you build is green before you contribute
|
55
|
+
your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
|
56
|
+
[Bundler](https://bundler.io/) installed. Then:
|
57
|
+
|
58
|
+
```
|
59
|
+
$ bundle update
|
60
|
+
$ rake
|
61
|
+
```
|
62
|
+
|
63
|
+
If it's clean and you don't see any error messages, submit your pull request.
|
50
64
|
|
51
65
|
# License
|
52
66
|
|
data/lib/random-port/pool.rb
CHANGED
@@ -26,38 +26,36 @@ require 'socket'
|
|
26
26
|
|
27
27
|
module RandomPort
|
28
28
|
# Pool of TPC ports.
|
29
|
+
#
|
30
|
+
# The class is NOT thread-safe!
|
31
|
+
#
|
29
32
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
33
|
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
31
34
|
# License:: MIT
|
32
35
|
class Pool
|
33
36
|
def initialize
|
34
37
|
@ports = []
|
35
|
-
@mutex = Mutex.new
|
36
38
|
end
|
37
39
|
|
38
40
|
# Application wide pool of ports
|
39
41
|
SINGLETON = Pool.new
|
40
42
|
|
41
43
|
def acquire
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
break
|
53
|
-
end
|
44
|
+
loop do
|
45
|
+
server = TCPServer.new('127.0.0.1', 0)
|
46
|
+
port = server.addr[1]
|
47
|
+
server.close
|
48
|
+
next if @ports.include?(port)
|
49
|
+
@ports << port
|
50
|
+
return port unless block_given?
|
51
|
+
yield port
|
52
|
+
@ports.delete(port)
|
53
|
+
break
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def release(port)
|
58
|
-
@
|
59
|
-
@ports.delete(port)
|
60
|
-
end
|
58
|
+
@ports.delete(port)
|
61
59
|
end
|
62
60
|
end
|
63
61
|
end
|
data/random-port.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.rubygems_version = '2.3.3'
|
32
32
|
s.required_ruby_version = '>=2.3'
|
33
33
|
s.name = 'random-port'
|
34
|
-
s.version = '0.
|
34
|
+
s.version = '0.3.0'
|
35
35
|
s.license = 'MIT'
|
36
36
|
s.summary = 'Random TCP port'
|
37
37
|
s.description = 'Reserves a random TCP port'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: random-port
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.7.6
|
125
125
|
signing_key:
|
126
126
|
specification_version: 2
|
127
127
|
summary: Random TCP port
|