17
17
18
18
Client <- Service : Close
19
19
"""
20
+
20
21
import time
21
22
from io import BytesIO
22
23
from hashlib import md5
27
28
from DIRAC .FrameworkSystem .Client .Logger import gLogger
28
29
from DIRAC .Core .Utilities import MixedEncode
29
30
31
+ # https://datatracker.ietf.org/doc/html/rfc8446#section-5.1
32
+ TLS_PAYLOAD_SIZE = 16384
33
+
30
34
31
35
class BaseTransport :
32
36
"""Invokes MixedEncode for marshaling/unmarshaling of data calls in transit"""
@@ -198,7 +202,7 @@ def receiveData(self, maxBufferSize=0, blockAfterKeepAlive=True, idleReceive=Fal
198
202
isKeepAlive = self .byteStream .find (BaseTransport .keepAliveMagic , 0 , keepAliveMagicLen ) == 0
199
203
# While not found the message length or the ka, keep receiving
200
204
while iSeparatorPosition == - 1 and not isKeepAlive :
201
- retVal = self ._read (16384 )
205
+ retVal = self ._read (TLS_PAYLOAD_SIZE )
202
206
# If error return
203
207
if not retVal ["OK" ]:
204
208
return retVal
@@ -225,6 +229,7 @@ def receiveData(self, maxBufferSize=0, blockAfterKeepAlive=True, idleReceive=Fal
225
229
pkgSize = int (self .byteStream [:iSeparatorPosition ])
226
230
pkgData = self .byteStream [iSeparatorPosition + 1 :]
227
231
readSize = len (pkgData )
232
+
228
233
if readSize >= pkgSize :
229
234
# If we already have all the data we need
230
235
data = pkgData [:pkgSize ]
@@ -235,7 +240,7 @@ def receiveData(self, maxBufferSize=0, blockAfterKeepAlive=True, idleReceive=Fal
235
240
pkgMem .write (pkgData )
236
241
# Receive while there's still data to be received
237
242
while readSize < pkgSize :
238
- retVal = self ._read (pkgSize - readSize , skipReadyCheck = True )
243
+ retVal = self ._read (min ( TLS_PAYLOAD_SIZE , pkgSize - readSize ) , skipReadyCheck = True )
239
244
if not retVal ["OK" ]:
240
245
return retVal
241
246
if not retVal ["Value" ]:
0 commit comments