Tests added, see the documentation in the tests directory for details. Improved the socket code.

This commit is contained in:
Storm Dragon
2025-12-03 02:51:49 -05:00
parent 2092a3e257
commit bf0d134187
12 changed files with 1622 additions and 30 deletions

View File

@@ -4,5 +4,5 @@
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributors.
version = "2025.12.02"
version = "2025.12.03"
code_name = "testing"

View File

@@ -30,6 +30,7 @@ class driver(remoteDriver):
# echo "command say this is a test" | nc localhost 22447
self.fenrirSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.fenrirSock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.fenrirSock.settimeout(5.0) # Prevent hanging on slow clients
self.host = "127.0.0.1"
self.port = self.env["runtime"]["SettingsManager"].get_setting_as_int(
"remote", "port"
@@ -45,33 +46,41 @@ class driver(remoteDriver):
continue
if self.fenrirSock in r:
client_sock, client_addr = self.fenrirSock.accept()
try:
rawdata = client_sock.recv(8129)
except Exception as e:
self.env["runtime"]["DebugManager"].write_debug_out(
"tcpDriver watch_dog: Error receiving data from client: "
+ str(e),
debug.DebugLevel.ERROR,
)
try:
data = rawdata.decode("utf-8").rstrip().lstrip()
event_queue.put(
{"Type": FenrirEventType.remote_incomming, "data": data}
)
except Exception as e:
self.env["runtime"]["DebugManager"].write_debug_out(
"tcpDriver watch_dog: Error decoding/queuing data: "
+ str(e),
debug.DebugLevel.ERROR,
)
try:
client_sock.close()
except Exception as e:
self.env["runtime"]["DebugManager"].write_debug_out(
"tcpDriver watch_dog: Error closing client socket: "
+ str(e),
debug.DebugLevel.ERROR,
)
# Ensure client socket is always closed to prevent resource
# leaks
try:
try:
rawdata = client_sock.recv(8129)
except Exception as e:
self.env["runtime"]["DebugManager"].write_debug_out(
"tcpDriver watch_dog: Error receiving data from "
"client: "
+ str(e),
debug.DebugLevel.ERROR,
)
rawdata = b"" # Set default empty data if recv fails
try:
data = rawdata.decode("utf-8").rstrip().lstrip()
event_queue.put(
{"Type": FenrirEventType.remote_incomming, "data": data}
)
except Exception as e:
self.env["runtime"]["DebugManager"].write_debug_out(
"tcpDriver watch_dog: Error decoding/queuing data: "
+ str(e),
debug.DebugLevel.ERROR,
)
finally:
# Always close client socket, even if data processing fails
try:
client_sock.close()
except Exception as e:
self.env["runtime"]["DebugManager"].write_debug_out(
"tcpDriver watch_dog: Error closing client socket: "
+ str(e),
debug.DebugLevel.ERROR,
)
if self.fenrirSock:
self.fenrirSock.close()
self.fenrirSock = None