ipc-client: add functions for send without receive

This commit is contained in:
progandy 2016-01-08 18:29:06 +01:00
parent 68da76b745
commit 227d9b82e4
2 changed files with 14 additions and 3 deletions

View file

@ -76,20 +76,26 @@ void free_ipc_response(struct ipc_response *response) {
free(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]; char data[ipc_header_size];
uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic));
memcpy(data, ipc_magic, sizeof(ipc_magic)); memcpy(data, ipc_magic, sizeof(ipc_magic));
data32[0] = *len; data32[0] = len;
data32[1] = type; data32[1] = type;
if (write(socketfd, data, ipc_header_size) == -1) { if (write(socketfd, data, ipc_header_size) == -1) {
sway_abort("Unable to send IPC header"); 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"); 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); struct ipc_response *resp = ipc_recv_response(socketfd);
char *response = resp->payload; char *response = resp->payload;

View file

@ -21,6 +21,11 @@ char *get_socketpath(void);
* Opens the sway socket. * Opens the sway socket.
*/ */
int ipc_open_socket(const char *socket_path); 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 * Issues a single IPC command and returns the buffer. len will be updated with
* the length of the buffer returned from sway. * the length of the buffer returned from sway.