File tree Expand file tree Collapse file tree 5 files changed +33
-4
lines changed Expand file tree Collapse file tree 5 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,17 @@ def test_create_server_4(self):
177
177
self .loop .run_until_complete (
178
178
self .loop .create_server (object , * addr ))
179
179
180
+ def test_create_server_5 (self ):
181
+ port = tb .find_free_port ()
182
+
183
+ async def runner ():
184
+ srv = await self .loop .create_server (
185
+ asyncio .Protocol ,
186
+ None , port )
187
+ srv .close ()
188
+
189
+ self .loop .run_until_complete (runner ())
190
+
180
191
def test_create_connection_1 (self ):
181
192
CNT = 0
182
193
TOTAL_CNT = 100
Original file line number Diff line number Diff line change @@ -85,6 +85,19 @@ def filter(self, record):
85
85
logger .removeFilter (filter )
86
86
87
87
88
+ def find_free_port (start_from = 50000 ):
89
+ for port in range (start_from , start_from + 500 ):
90
+ sock = socket .socket ()
91
+ with sock :
92
+ try :
93
+ sock .bind (('' , port ))
94
+ except socket .error :
95
+ continue
96
+ else :
97
+ return port
98
+ raise RuntimeError ('could not find a free port' )
99
+
100
+
88
101
class SSLTestCase :
89
102
90
103
ONLYCERT = _cert_fullname ('ssl_cert.pem' )
Original file line number Diff line number Diff line change @@ -42,9 +42,7 @@ cdef ft_partial = functools.partial
42
42
43
43
cdef iter_chain = itertools.chain
44
44
45
- cdef int has_AF_INET6 = hasattr (socket, ' AF_INET6' )
46
45
cdef int has_SO_REUSEPORT = hasattr (socket, ' SO_REUSEPORT' )
47
- cdef int has_IPPROTO_IPV6 = hasattr (socket, ' IPPROTO_IPV6' )
48
46
cdef int SO_REUSEPORT = getattr (socket, ' SO_REUSEPORT' , 0 )
49
47
50
48
cdef socket_gaierror = socket.gaierror
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ cdef extern from "includes/compat.h":
11
11
12
12
13
13
cdef extern from " uv.h" nogil:
14
+ cdef int UV_TCP_IPV6ONLY
15
+
14
16
cdef int UV_EACCES
15
17
cdef int UV_EAGAIN
16
18
cdef int UV_EALREADY
@@ -57,7 +59,6 @@ cdef extern from "uv.h" nogil:
57
59
cdef int AI_PASSIVE
58
60
cdef int AI_NUMERICHOST
59
61
cdef int INET6_ADDRSTRLEN
60
- cdef int IPV6_V6ONLY
61
62
cdef int IPPROTO_IPV6
62
63
cdef int SOCK_STREAM
63
64
cdef int SOCK_DGRAM
Original file line number Diff line number Diff line change @@ -1121,6 +1121,7 @@ cdef class Loop:
1121
1121
TCPServer tcp
1122
1122
system.addrinfo * addrinfo
1123
1123
Server server = Server(self )
1124
+ int bind_flags
1124
1125
1125
1126
if ssl is not None and not isinstance (ssl, ssl_SSLContext):
1126
1127
raise TypeError (' ssl argument must be an SSLContext or None' )
@@ -1163,8 +1164,13 @@ cdef class Loop:
1163
1164
if reuse_port:
1164
1165
self ._sock_set_reuseport(tcp._fileno())
1165
1166
1167
+ if addrinfo.ai_family == uv.AF_INET6:
1168
+ bind_flags = uv.UV_TCP_IPV6ONLY
1169
+ else :
1170
+ bind_flags = 0
1171
+
1166
1172
try :
1167
- tcp.bind(addrinfo.ai_addr)
1173
+ tcp.bind(addrinfo.ai_addr, bind_flags )
1168
1174
tcp.listen(backlog)
1169
1175
except OSError as err:
1170
1176
pyaddr = __convert_sockaddr_to_pyaddr(
You can’t perform that action at this time.
0 commit comments