summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-11-18 15:37:05 -0600
committerJohn Estabrook <jestabro@vyos.io>2024-11-19 06:46:09 -0600
commitf38a402f158dad178165e330f292393278705281 (patch)
tree55c77710e13b98b41f0c141dcd22752502aa8e7c /src/services
parent99f414cc69730cb5a33c6d1891e6f7e5e4f3dd16 (diff)
downloadvyos-1x-f38a402f158dad178165e330f292393278705281.tar.gz
vyos-1x-f38a402f158dad178165e330f292393278705281.zip
configd: T6899: use multipart message instead of extra exchange
Diffstat (limited to 'src/services')
-rwxr-xr-xsrc/services/vyos-configd28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/services/vyos-configd b/src/services/vyos-configd
index cb23642dc..d977ba2cb 100755
--- a/src/services/vyos-configd
+++ b/src/services/vyos-configd
@@ -56,6 +56,7 @@ else:
SOCKET_PATH = 'ipc:///run/vyos-configd.sock'
MAX_MSG_SIZE = 65535
+PAD_MSG_SIZE = 6
# Response error codes
R_SUCCESS = 1
@@ -256,25 +257,14 @@ def process_node_data(config, data, _last: bool = False) -> tuple[int, str]:
def send_result(sock, err, msg):
- msg_size = min(MAX_MSG_SIZE, len(msg)) if msg else 0
-
- err_rep = err.to_bytes(1, byteorder=sys.byteorder)
- logger.debug(f'Sending reply: {err}')
- sock.send(err_rep)
-
- # size req from vyshim client
- size_req = sock.recv().decode()
- logger.debug(f'Received request: {size_req}')
- msg_size_rep = hex(msg_size).encode()
- sock.send(msg_size_rep)
- logger.debug(f'Sending reply: {msg_size}')
-
- if msg_size > 0:
- # send req is sent from vyshim client only if msg_size > 0
- send_req = sock.recv().decode()
- logger.debug(f'Received request: {send_req}')
- sock.send(msg.encode())
- logger.debug('Sending reply with output')
+ msg = msg if msg else ''
+ msg_size = min(MAX_MSG_SIZE, len(msg))
+
+ err_rep = err.to_bytes(1)
+ msg_size_rep = f'{msg_size:#0{PAD_MSG_SIZE}x}'
+
+ logger.debug(f'Sending reply: error_code {err} with output')
+ sock.send_multipart([err_rep, msg_size_rep.encode(), msg.encode()])
write_stdout_log(script_stdout_log, msg)