@@ -328,7 +328,14 @@ def readAsync(self, max=None, min=1):
328328 allowedTypes = ContentType .application_data
329329 allowedHsTypes = None
330330 try :
331- while len (self ._readBuffer ) < min and not self .closed :
331+ try_once = True
332+ # perform a read even if we were asked to read 0 bytes, but only
333+ # if the buffer is empty; this is used to trigger
334+ # processing of NST, KeyUpdate and PHA
335+ while (len (self ._readBuffer ) < min or
336+ (not self ._readBuffer and try_once )) \
337+ and not self .closed :
338+ try_once = False
332339 try :
333340 for result in self ._getMsg (allowedTypes ,
334341 allowedHsTypes ,
@@ -338,21 +345,19 @@ def readAsync(self, max=None, min=1):
338345 if isinstance (result , NewSessionTicket ):
339346 result .time = time .time ()
340347 self .tickets .append (result )
341- continue
342348 elif isinstance (result , KeyUpdate ):
343349 for result in self ._handle_keyupdate_request (result ):
344350 yield result
345- continue
346351 elif isinstance (result , Certificate ):
347352 for result in self ._handle_srv_pha (result ):
348353 yield result
349- continue
350354 elif isinstance (result , CertificateRequest ):
351355 for result in self ._handle_pha (result ):
352356 yield result
353- continue
354- applicationData = result
355- self ._readBuffer += applicationData .write ()
357+ else :
358+ assert isinstance (result , ApplicationData )
359+ applicationData = result
360+ self ._readBuffer += applicationData .write ()
356361 except TLSRemoteAlert as alert :
357362 if alert .description != AlertDescription .close_notify :
358363 raise
0 commit comments