CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/support/acceptance/port_allocator.rb
Views: 1904
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