Skip to content

Commit 8625092

Browse files
committed
Use DELIM to indicate the end of a message over the control socket
1 parent 079ced5 commit 8625092

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

receptor/controller.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ def send_directive(directive, recipient, payload, sock):
1919
payload = sys.stdin.read()
2020
sock.sendall(f"{recipient}\n{directive}\n{payload}".encode('utf-8') + protocol.DELIM)
2121
response = b''
22-
response = sock.recv(4096)
22+
while True:
23+
received = sock.recv(1024)
24+
done = protocol.DELIM in received
25+
response += received.rstrip(protocol.DELIM)
26+
if done:
27+
break
28+
2329
return response
2430

2531
# FIXME: the socket path is in the config, it shouldn't need to be passed as an arg here

receptor/protocol.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import uuid
88

99
from collections import deque
10+
1011
from .messages import envelope
1112
from .exceptions import ReceptorBufferError
1213

@@ -172,7 +173,7 @@ def emit_response(self, response):
172173
self.transport.write(json.dumps(dict(timestamp=response.timestamp,
173174
in_response_to=response.in_response_to,
174175
payload=response.raw_payload,
175-
code=response.code)).encode())
176+
code=response.code)).encode() + DELIM)
176177

177178
def data_received(self, data):
178179
recipient, directive, payload = data.rstrip(DELIM).decode('utf8').split('\n', 2)
@@ -212,6 +213,6 @@ def data_received_callback(self, inner_env, fut):
212213
payload=str(e),
213214
code=1,
214215
)
215-
).encode()
216+
).encode() + DELIM
216217
)
217218

0 commit comments

Comments
 (0)