Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita7662d1

Browse files
[#256] Port number 65535 is valid for using (#268)
This patch corrects PortManager__Generic: - Valid port range is [1024, 65535]. Old range was [1024, 65535) - Strange (copy&paste) code for self._available_ports initialization is corrected - Strange (copy&paste) code for self._reserved_ports initialization is corrected - New asserts are added
1 parent44d61c2 commita7662d1

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

‎testgres/impl/port_manager__generic.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,31 @@
99

1010

1111
classPortManager__Generic(PortManager):
12+
_C_MIN_PORT_NUMBER=1024
13+
_C_MAX_PORT_NUMBER=65535
14+
1215
_os_ops:OsOperations
1316
_guard:object
1417
# TODO: is there better to use bitmap fot _available_ports?
1518
_available_ports:typing.Set[int]
1619
_reserved_ports:typing.Set[int]
1720

1821
def__init__(self,os_ops:OsOperations):
22+
assert__class__._C_MIN_PORT_NUMBER<=__class__._C_MAX_PORT_NUMBER
23+
1924
assertos_opsisnotNone
2025
assertisinstance(os_ops,OsOperations)
2126
self._os_ops=os_ops
2227
self._guard=threading.Lock()
23-
self._available_ports:typing.Set[int]=set(range(1024,65535))
24-
self._reserved_ports:typing.Set[int]=set()
28+
29+
self._available_ports=set(
30+
range(__class__._C_MIN_PORT_NUMBER,__class__._C_MAX_PORT_NUMBER+1)
31+
)
32+
assertlen(self._available_ports)== (
33+
(__class__._C_MAX_PORT_NUMBER-__class__._C_MIN_PORT_NUMBER)+1
34+
)
35+
self._reserved_ports=set()
36+
return
2537

2638
defreserve_port(self)->int:
2739
assertself._guardisnotNone
@@ -35,9 +47,13 @@ def reserve_port(self) -> int:
3547
t=None
3648

3749
forportinsampled_ports:
50+
asserttype(port)==int# noqa: E721
3851
assertnot (portinself._reserved_ports)
3952
assertportinself._available_ports
4053

54+
assertport>=__class__._C_MIN_PORT_NUMBER
55+
assertport<=__class__._C_MAX_PORT_NUMBER
56+
4157
ifnotself._os_ops.is_port_free(port):
4258
continue
4359

@@ -51,6 +67,8 @@ def reserve_port(self) -> int:
5167

5268
defrelease_port(self,number:int)->None:
5369
asserttype(number)==int# noqa: E721
70+
assertnumber>=__class__._C_MIN_PORT_NUMBER
71+
assertnumber<=__class__._C_MAX_PORT_NUMBER
5472

5573
assertself._guardisnotNone
5674
asserttype(self._reserved_ports)==set# noqa: E721
@@ -62,3 +80,4 @@ def release_port(self, number: int) -> None:
6280
self._reserved_ports.discard(number)
6381
assertnot (numberinself._reserved_ports)
6482
assertnumberinself._available_ports
83+
return

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp