Github Mirror / telegraf-plugins: 64646e96




Add a small semblence of protocol awareness to the socket reads (utilities/telegraf-plugins#6)

Add a small semblence of protocol awareness to the socket reads (utilities/telegraf-plugins#6)

The end of any (successful) message from the daemon will be "250 OK". We check for this so we can avoid trying to read from the socket again (incurring a time penalty the length of a timeout)

Commit 64646e96.

Authored 2022-06-15T18:16:27.000+01:00 by B Tasker in project Github Mirror / telegraf-plugins

+8 lines -1 lines

Commit Signature

Changes

diff --git a/tor-daemon/tor-daemon.py b/tor-daemon/tor-daemon.py
--- a/tor-daemon/tor-daemon.py
+++ b/tor-daemon/tor-daemon.py
# @@ -51,7 +51,14 @@ def send_and_respond(sock, command):
# data = sock.recv(1024)
# if not data:
# break
# - res.append(data.decode())
# + l = data.decode()
# + res.append(l)
# +
# + if l.startswith("250 OK\r\n") or l.endswith("250 OK\r\n"):
# + # We've reached the end of the message
# + print("EOM")
# + break
# +
# except socket.timeout as e:
# if e.args[0] == "timed out":
# if len(res) == 0 and read_attempts < 2 and len(res) == 0:
#