improve connection timeout handling
This commit is contained in:
parent
48dc75c728
commit
5b92c317c1
@ -16,7 +16,7 @@ from owrx.waterfall import WaterfallOptions
|
||||
from owrx.websocket import Handler
|
||||
from queue import Queue, Full, Empty
|
||||
from js8py import Js8Frame
|
||||
from abc import ABC, ABCMeta, abstractmethod
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import json
|
||||
import threading
|
||||
|
||||
@ -517,6 +517,7 @@ class HandshakeMessageHandler(Handler):
|
||||
logger.warning("invalid connection type: %s", handshake["type"])
|
||||
|
||||
if client is not None:
|
||||
logger.debug("handing off connection handling to %s", type(client).__name__)
|
||||
# hand off all further communication to the correspondig connection
|
||||
conn.send("CLIENT DE SERVER server=openwebrx version={version}".format(version=openwebrx_version))
|
||||
conn.setMessageHandler(client)
|
||||
|
@ -137,10 +137,10 @@ class WebSocketConnection(object):
|
||||
self._sendBytes(data_to_send)
|
||||
|
||||
def _sendBytes(self, data_to_send):
|
||||
def chunks(l, n):
|
||||
"""Yield successive n-sized chunks from l."""
|
||||
for i in range(0, len(l), n):
|
||||
yield l[i : i + n]
|
||||
def chunks(input, n):
|
||||
"""Yield successive n-sized chunks from input."""
|
||||
for i in range(0, len(input), n):
|
||||
yield input[i: i + n]
|
||||
|
||||
try:
|
||||
with self.sendLock:
|
||||
@ -151,9 +151,11 @@ class WebSocketConnection(object):
|
||||
if written != len(chunk):
|
||||
logger.error("incomplete write! closing socket!")
|
||||
self.close()
|
||||
break
|
||||
else:
|
||||
logger.debug("socket not returned from select; closing")
|
||||
self.close()
|
||||
break
|
||||
# these exception happen when the socket is closed
|
||||
except OSError:
|
||||
logger.exception("OSError while writing data")
|
||||
@ -215,8 +217,9 @@ class WebSocketConnection(object):
|
||||
if mask:
|
||||
masking_key = protected_read(4)
|
||||
data = protected_read(length)
|
||||
if mask:
|
||||
data = bytes([b ^ masking_key[index % 4] for (index, b) in enumerate(data)])
|
||||
else:
|
||||
data = protected_read(length)
|
||||
if opcode == OPCODE_TEXT_MESSAGE:
|
||||
message = data.decode("utf-8")
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user