Skip to content

Commit

Permalink
Merge pull request #4 from PaulWieland/master
Browse files Browse the repository at this point in the history
Two small fixes to enable reconnecting and prevent forked process from hanging at 100% cpu
  • Loading branch information
Neustradamus committed Mar 21, 2021
2 parents 6cae7a2 + e39758a commit d28733e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ap2-receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def do_GET_PARAMETER(self):
else:
print("Ops GET_PARAMETER: %s" % p)
if DISABLE_VM:
res = b"volume: 0"
res = b"volume: 0" + b"\r\n"
else:
res = b"\r\n".join(b"%s: %s" % (k, v) for k, v in params_res.items()) + b"\r\n"
self.send_response(200)
Expand All @@ -342,6 +342,7 @@ def do_GET_PARAMETER(self):
self.send_header("Server", self.version_string())
self.send_header("CSeq", self.headers["CSeq"])
self.end_headers()
hexdump(res);
self.wfile.write(res)

def do_SET_PARAMETER(self):
Expand Down Expand Up @@ -440,6 +441,12 @@ def do_TEARDOWN(self):
self.send_header("Server", self.version_string())
self.send_header("CSeq", self.headers["CSeq"])
self.end_headers()

# Erase the hap() instance, otherwise reconnects fail
self.server.hap = None

# terminate the forked event_proc, otherwise a zombie process consumes 100% cpu
self.event_proc.terminate()

def do_SETPEERS(self):
print("SETPEERS %s" % self.path)
Expand Down Expand Up @@ -615,7 +622,7 @@ def handle_info(self):
print("Content-Type: %s | Not implemented" % self.headers["Content-Type"])
self.send_error(404)
else:
res = writePlistToString(second_stage_info)
res = writePlistToString(sonos_one_info)
self.send_response(200)
self.send_header("Content-Length", len(res))
self.send_header("Content-Type", HTTP_CT_BPLIST)
Expand Down

0 comments on commit d28733e

Please sign in to comment.