From 227d9b82e4475c4789f2e9b5ff5409df50271e19 Mon Sep 17 00:00:00 2001 From: progandy Date: Fri, 8 Jan 2016 18:29:06 +0100 Subject: [PATCH] ipc-client: add functions for send without receive --- common/ipc-client.c | 12 +++++++++--- include/ipc-client.h | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/ipc-client.c b/common/ipc-client.c index 81348913..acf7ae84 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c @@ -76,20 +76,26 @@ void free_ipc_response(struct ipc_response *response) { free(response); } -char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { +void ipc_send_command(int socketfd, uint32_t type, const char *payload, uint32_t len) { + char data[ipc_header_size]; uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); memcpy(data, ipc_magic, sizeof(ipc_magic)); - data32[0] = *len; + data32[0] = len; data32[1] = type; if (write(socketfd, data, ipc_header_size) == -1) { sway_abort("Unable to send IPC header"); } - if (write(socketfd, payload, *len) == -1) { + if (write(socketfd, payload, len) == -1) { sway_abort("Unable to send IPC payload"); } +} + +char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { + + ipc_send_command(socketfd, type, payload, *len); struct ipc_response *resp = ipc_recv_response(socketfd); char *response = resp->payload; diff --git a/include/ipc-client.h b/include/ipc-client.h index 030c80b6..141e18e8 100644 --- a/include/ipc-client.h +++ b/include/ipc-client.h @@ -21,6 +21,11 @@ char *get_socketpath(void); * Opens the sway socket. */ int ipc_open_socket(const char *socket_path); +/** + * Issues a single IPC command without waiting for a response. + * Useful if events are sent on the same socket. + */ +void ipc_send_command(int socketfd, uint32_t type, const char *payload, uint32_t len); /** * Issues a single IPC command and returns the buffer. len will be updated with * the length of the buffer returned from sway.