1
0
This commit is contained in:
2026-01-08 20:25:33 +08:00
parent 886e0caab2
commit 55ed60c643
7 changed files with 50 additions and 55 deletions

View File

@@ -92,10 +92,10 @@ class CmdServer:
if self.__status != ServerStatus.Running:
raise RuntimeError("unexpected server status")
# If there is stop requested, we post it first and return
# If there is stop requested from us,
# we order Presenter exit and enter next step.
if request_stop:
self.__wait_stop()
return True
self.__pipe_operator.write(CODE_PACKER.pack(ProtocolCode.STOP_REQUEST))
while True:
# Wait for code from Presenter
@@ -115,26 +115,12 @@ class CmdServer:
case ProtocolCode.ACTIVELY_STOP:
# Presenter requested stop.
# Agree with it, send code and wait response
self.__wait_stop()
return True
case _:
raise RuntimeError("unexpected protocol code when running")
def __wait_stop(self) -> None:
# Send stop request code
self.__pipe_operator.write(CODE_PACKER.pack(ProtocolCode.STOP_REQUEST))
# Wait stop response code
while True:
# Accept code
code_bytes = self.__pipe_operator.read(CODE_PACKER.size)
(code,) = CODE_PACKER.unpack(code_bytes)
# Check whether it is stop response
match ProtocolCode(code):
self.__pipe_operator.write(
CODE_PACKER.pack(ProtocolCode.STOP_REQUEST)
)
case ProtocolCode.STOP_RESPONSE:
# Set self status and return
self.__status = ServerStatus.Stop
return
return True
case _:
raise RuntimeError("unexpected protocol code when waiting quit")
raise RuntimeError("unexpected protocol code when running")