@@ -269,7 +269,7 @@ async def restore(self):
269
269
class Server (events .AbstractServer ):
270
270
271
271
def __init__ (self , loop , sockets , protocol_factory , ssl_context , backlog ,
272
- ssl_handshake_timeout ):
272
+ ssl_handshake_timeout , ssl_shutdown_timeout = None ):
273
273
self ._loop = loop
274
274
self ._sockets = sockets
275
275
self ._active_count = 0
@@ -278,6 +278,7 @@ def __init__(self, loop, sockets, protocol_factory, ssl_context, backlog,
278
278
self ._backlog = backlog
279
279
self ._ssl_context = ssl_context
280
280
self ._ssl_handshake_timeout = ssl_handshake_timeout
281
+ self ._ssl_shutdown_timeout = ssl_shutdown_timeout
281
282
self ._serving = False
282
283
self ._serving_forever_fut = None
283
284
@@ -309,7 +310,8 @@ def _start_serving(self):
309
310
sock .listen (self ._backlog )
310
311
self ._loop ._start_serving (
311
312
self ._protocol_factory , sock , self ._ssl_context ,
312
- self , self ._backlog , self ._ssl_handshake_timeout )
313
+ self , self ._backlog , self ._ssl_handshake_timeout ,
314
+ self ._ssl_shutdown_timeout )
313
315
314
316
def get_loop (self ):
315
317
return self ._loop
@@ -463,6 +465,7 @@ def _make_ssl_transport(
463
465
* , server_side = False , server_hostname = None ,
464
466
extra = None , server = None ,
465
467
ssl_handshake_timeout = None ,
468
+ ssl_shutdown_timeout = None ,
466
469
call_connection_made = True ):
467
470
"""Create SSL transport."""
468
471
raise NotImplementedError
@@ -965,6 +968,7 @@ async def create_connection(
965
968
proto = 0 , flags = 0 , sock = None ,
966
969
local_addr = None , server_hostname = None ,
967
970
ssl_handshake_timeout = None ,
971
+ ssl_shutdown_timeout = None ,
968
972
happy_eyeballs_delay = None , interleave = None ):
969
973
"""Connect to a TCP server.
970
974
@@ -1000,6 +1004,10 @@ async def create_connection(
1000
1004
raise ValueError (
1001
1005
'ssl_handshake_timeout is only meaningful with ssl' )
1002
1006
1007
+ if ssl_shutdown_timeout is not None and not ssl :
1008
+ raise ValueError (
1009
+ 'ssl_shutdown_timeout is only meaningful with ssl' )
1010
+
1003
1011
if happy_eyeballs_delay is not None and interleave is None :
1004
1012
# If using happy eyeballs, default to interleave addresses by family
1005
1013
interleave = 1
@@ -1075,7 +1083,8 @@ async def create_connection(
1075
1083
1076
1084
transport , protocol = await self ._create_connection_transport (
1077
1085
sock , protocol_factory , ssl , server_hostname ,
1078
- ssl_handshake_timeout = ssl_handshake_timeout )
1086
+ ssl_handshake_timeout = ssl_handshake_timeout ,
1087
+ ssl_shutdown_timeout = ssl_shutdown_timeout )
1079
1088
if self ._debug :
1080
1089
# Get the socket from the transport because SSL transport closes
1081
1090
# the old socket and creates a new SSL socket
@@ -1087,7 +1096,8 @@ async def create_connection(
1087
1096
async def _create_connection_transport (
1088
1097
self , sock , protocol_factory , ssl ,
1089
1098
server_hostname , server_side = False ,
1090
- ssl_handshake_timeout = None ):
1099
+ ssl_handshake_timeout = None ,
1100
+ ssl_shutdown_timeout = None ):
1091
1101
1092
1102
sock .setblocking (False )
1093
1103
@@ -1098,7 +1108,8 @@ async def _create_connection_transport(
1098
1108
transport = self ._make_ssl_transport (
1099
1109
sock , protocol , sslcontext , waiter ,
1100
1110
server_side = server_side , server_hostname = server_hostname ,
1101
- ssl_handshake_timeout = ssl_handshake_timeout )
1111
+ ssl_handshake_timeout = ssl_handshake_timeout ,
1112
+ ssl_shutdown_timeout = ssl_shutdown_timeout )
1102
1113
else :
1103
1114
transport = self ._make_socket_transport (sock , protocol , waiter )
1104
1115
@@ -1189,7 +1200,8 @@ async def _sendfile_fallback(self, transp, file, offset, count):
1189
1200
async def start_tls (self , transport , protocol , sslcontext , * ,
1190
1201
server_side = False ,
1191
1202
server_hostname = None ,
1192
- ssl_handshake_timeout = None ):
1203
+ ssl_handshake_timeout = None ,
1204
+ ssl_shutdown_timeout = None ):
1193
1205
"""Upgrade transport to TLS.
1194
1206
1195
1207
Return a new transport that *protocol* should start using
@@ -1212,6 +1224,7 @@ async def start_tls(self, transport, protocol, sslcontext, *,
1212
1224
self , protocol , sslcontext , waiter ,
1213
1225
server_side , server_hostname ,
1214
1226
ssl_handshake_timeout = ssl_handshake_timeout ,
1227
+ ssl_shutdown_timeout = ssl_shutdown_timeout ,
1215
1228
call_connection_made = False )
1216
1229
1217
1230
# Pause early so that "ssl_protocol.data_received()" doesn't
@@ -1397,6 +1410,7 @@ async def create_server(
1397
1410
reuse_address = None ,
1398
1411
reuse_port = None ,
1399
1412
ssl_handshake_timeout = None ,
1413
+ ssl_shutdown_timeout = None ,
1400
1414
start_serving = True ):
1401
1415
"""Create a TCP server.
1402
1416
@@ -1420,6 +1434,10 @@ async def create_server(
1420
1434
raise ValueError (
1421
1435
'ssl_handshake_timeout is only meaningful with ssl' )
1422
1436
1437
+ if ssl_shutdown_timeout is not None and ssl is None :
1438
+ raise ValueError (
1439
+ 'ssl_shutdown_timeout is only meaningful with ssl' )
1440
+
1423
1441
if host is not None or port is not None :
1424
1442
if sock is not None :
1425
1443
raise ValueError (
@@ -1492,7 +1510,8 @@ async def create_server(
1492
1510
sock .setblocking (False )
1493
1511
1494
1512
server = Server (self , sockets , protocol_factory ,
1495
- ssl , backlog , ssl_handshake_timeout )
1513
+ ssl , backlog , ssl_handshake_timeout ,
1514
+ ssl_shutdown_timeout )
1496
1515
if start_serving :
1497
1516
server ._start_serving ()
1498
1517
# Skip one loop iteration so that all 'loop.add_reader'
@@ -1506,17 +1525,23 @@ async def create_server(
1506
1525
async def connect_accepted_socket (
1507
1526
self , protocol_factory , sock ,
1508
1527
* , ssl = None ,
1509
- ssl_handshake_timeout = None ):
1528
+ ssl_handshake_timeout = None ,
1529
+ ssl_shutdown_timeout = None ):
1510
1530
if sock .type != socket .SOCK_STREAM :
1511
1531
raise ValueError (f'A Stream Socket was expected, got { sock !r} ' )
1512
1532
1513
1533
if ssl_handshake_timeout is not None and not ssl :
1514
1534
raise ValueError (
1515
1535
'ssl_handshake_timeout is only meaningful with ssl' )
1516
1536
1537
+ if ssl_shutdown_timeout is not None and not ssl :
1538
+ raise ValueError (
1539
+ 'ssl_shutdown_timeout is only meaningful with ssl' )
1540
+
1517
1541
transport , protocol = await self ._create_connection_transport (
1518
1542
sock , protocol_factory , ssl , '' , server_side = True ,
1519
- ssl_handshake_timeout = ssl_handshake_timeout )
1543
+ ssl_handshake_timeout = ssl_handshake_timeout ,
1544
+ ssl_shutdown_timeout = ssl_shutdown_timeout )
1520
1545
if self ._debug :
1521
1546
# Get the socket from the transport because SSL transport closes
1522
1547
# the old socket and creates a new SSL socket
0 commit comments