@@ -141,6 +141,17 @@ def __init__(self, sock, protocols=None, extensions=None, environ=None, heartbea
141141 "Internal buffer to get around SSL problems"
142142 self .buf = b''
143143
144+ self .sock_timeout = None
145+ """
146+ Used to set socket.settimeout(value):
147+ From: https://docs.python.org/3.11/library/socket.html#socket.socket.settimeout
148+ The value argument can be a nonnegative floating point number expressing seconds, or None.
149+ If a non-zero value is given, subsequent socket operations will raise a timeout exception
150+ if the timeout period value has elapsed before the operation has completed.
151+ If zero is given, the socket is put in non-blocking mode.
152+ If None is given, the socket is put in blocking mode.
153+ """
154+
144155 self ._local_address = None
145156 self ._peer_address = None
146157
@@ -515,10 +526,12 @@ def run(self):
515526 we initiate the closing of the connection with the
516527 appropiate error code.
517528
518- This method is blocking and should likely be run
519- in a thread.
529+ The self.sock_timeout determines whether this method
530+ is blocking, or can timeout on reads. If a timeout
531+ occurs, the unhandled_error function will be called
532+ It should likely be run in a thread.
520533 """
521- self .sock .setblocking ( True )
534+ self .sock .settimeout ( self . sock_timeout )
522535 with Heartbeat (self , frequency = self .heartbeat_freq ):
523536 s = self .stream
524537
0 commit comments