Skip to content

Commit

Permalink
fix notifications ruining heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveicedgreentea committed Jan 15, 2023
1 parent 3999a2e commit 8c05543
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions madvr/madvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,30 +181,28 @@ def _send_heartbeat(self) -> None:

self.client.send(self.HEARTBEAT)

# read first 4 bytes for ok\r\n
ack_reply = self.client.recv(4)
# read all to clear buffer
ack_reply = self.client.recv(self.read_limit)

if ack_reply != ACKs.reply.value:
raise HeartBeatError(f"{ack_reply} does not match {ACKs.reply.value}")
if ACKs.reply.value not in ack_reply:
raise HeartBeatError(f"{ack_reply} did not contain {ACKs.reply.value}")

# send heartbeat with notification and read ack and then regular client
# ensure both work one after the next
self.notification_client.send(self.HEARTBEAT)

# read first 4 bytes for ok\r\n
ack_reply = self.notification_client.recv(4)
ack_reply = self.notification_client.recv(self.read_limit)

if ack_reply != ACKs.reply.value:
raise HeartBeatError(f"{ack_reply} does not match {ACKs.reply.value}")
if ACKs.reply.value not in ack_reply:
raise HeartBeatError(f"{ack_reply} did not contain {ACKs.reply.value}")

# send again on regular client to make sure both clients work
self.client.send(self.HEARTBEAT)

# read first 4 bytes for ok\r\n
ack_reply = self.client.recv(4)
ack_reply = self.client.recv(self.read_limit)

if ack_reply != ACKs.reply.value:
raise HeartBeatError(f"{ack_reply} does not match {ACKs.reply.value}")
if ACKs.reply.value not in ack_reply:
raise HeartBeatError(f"{ack_reply} did not contain {ACKs.reply.value}")

self.logger.debug("Handshakes complete")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="py_madvr",
version="1.1.5",
version="1.1.6",
author="iloveicedgreentea",
description="A package to control MadVR Envy over IP",
long_description=long_description,
Expand Down

0 comments on commit 8c05543

Please sign in to comment.