Pass the peer id to python for potentially async replies

This commit is contained in:
Kovid Goyal
2021-10-30 08:31:13 +05:30
parent ee852cf5fc
commit 3553b3ce3d
2 changed files with 6 additions and 5 deletions

View File

@@ -451,7 +451,7 @@ class Boss:
tb = traceback.format_exc()
self.show_error(_('remote_control mapping failed'), tb)
def peer_message_received(self, msg_bytes: bytes) -> Optional[bytes]:
def peer_message_received(self, msg_bytes: bytes, peer_id: int) -> Optional[bytes]:
cmd_prefix = b'\x1bP@kitty-cmd'
terminator = b'\x1b\\'
if msg_bytes.startswith(cmd_prefix) and msg_bytes.endswith(terminator):

View File

@@ -418,13 +418,14 @@ parse_input(ChildMonitor *self) {
Message *msg = msgs + i;
PyObject *resp = NULL;
if (msg->data) {
resp = PyObject_CallMethod(global_state.boss, "peer_message_received", "y#", msg->data, (int)msg->sz);
resp = PyObject_CallMethod(global_state.boss, "peer_message_received", "y#K", msg->data, (int)msg->sz, msg->peer_id);
free(msg->data);
if (!resp) PyErr_Print();
}
if (resp && PyBytes_Check(resp)) send_response(msg->peer_id, PyBytes_AS_STRING(resp), PyBytes_GET_SIZE(resp));
else send_response(msg->peer_id, NULL, 0);
Py_CLEAR(resp);
if (resp) {
if (PyBytes_Check(resp)) send_response(msg->peer_id, PyBytes_AS_STRING(resp), PyBytes_GET_SIZE(resp));
Py_CLEAR(resp);
} else send_response(msg->peer_id, NULL, 0);
}
free(msgs); msgs = NULL;
}