1717
1818Client <- Service : Close
1919"""
20+
2021import time
2122from io import BytesIO
2223from hashlib import md5
2728from DIRAC .FrameworkSystem .Client .Logger import gLogger
2829from DIRAC .Core .Utilities import MixedEncode
2930
31+ # https://datatracker.ietf.org/doc/html/rfc8446#section-5.1
32+ TLS_PAYLOAD_SIZE = 16384
33+
3034
3135class BaseTransport :
3236 """Invokes MixedEncode for marshaling/unmarshaling of data calls in transit"""
@@ -198,7 +202,7 @@ def receiveData(self, maxBufferSize=0, blockAfterKeepAlive=True, idleReceive=Fal
198202 isKeepAlive = self .byteStream .find (BaseTransport .keepAliveMagic , 0 , keepAliveMagicLen ) == 0
199203 # While not found the message length or the ka, keep receiving
200204 while iSeparatorPosition == - 1 and not isKeepAlive :
201- retVal = self ._read (16384 )
205+ retVal = self ._read (TLS_PAYLOAD_SIZE )
202206 # If error return
203207 if not retVal ["OK" ]:
204208 return retVal
@@ -225,6 +229,7 @@ def receiveData(self, maxBufferSize=0, blockAfterKeepAlive=True, idleReceive=Fal
225229 pkgSize = int (self .byteStream [:iSeparatorPosition ])
226230 pkgData = self .byteStream [iSeparatorPosition + 1 :]
227231 readSize = len (pkgData )
232+
228233 if readSize >= pkgSize :
229234 # If we already have all the data we need
230235 data = pkgData [:pkgSize ]
@@ -235,7 +240,7 @@ def receiveData(self, maxBufferSize=0, blockAfterKeepAlive=True, idleReceive=Fal
235240 pkgMem .write (pkgData )
236241 # Receive while there's still data to be received
237242 while readSize < pkgSize :
238- retVal = self ._read (pkgSize - readSize , skipReadyCheck = True )
243+ retVal = self ._read (min ( TLS_PAYLOAD_SIZE , pkgSize - readSize ) , skipReadyCheck = True )
239244 if not retVal ["OK" ]:
240245 return retVal
241246 if not retVal ["Value" ]:
0 commit comments