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