CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/support/acceptance/port_allocator.rb
Views: 11780
1
module Acceptance
2
###
3
# A utility class for generating the next available bind port that is free
4
# on the host machine
5
###
6
class PortAllocator
7
def initialize(base = 6000)
8
@base = base
9
@current = base
10
end
11
12
# @return [Integer] The next available port that can be bound to on the host
13
def next
14
# TODO: In the future this could verify the port is free, and attempt to avoid TOCTTOU issues
15
@current += 1
16
end
17
end
18
end
19
20