diff options
Diffstat (limited to 'common/ipc-client.c')
-rw-r--r-- | common/ipc-client.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c index 5d2d5808..e92a09fe 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c | |||
@@ -39,20 +39,9 @@ int ipc_open_socket(const char *socket_path) { | |||
39 | return socketfd; | 39 | return socketfd; |
40 | } | 40 | } |
41 | 41 | ||
42 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { | 42 | char *ipc_recv_response(int socketfd, uint32_t *len) { |
43 | char data[ipc_header_size]; | 43 | char data[ipc_header_size]; |
44 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | 44 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); |
45 | memcpy(data, ipc_magic, sizeof(ipc_magic)); | ||
46 | data32[0] = *len; | ||
47 | data32[1] = type; | ||
48 | |||
49 | if (write(socketfd, data, ipc_header_size) == -1) { | ||
50 | sway_abort("Unable to send IPC header"); | ||
51 | } | ||
52 | |||
53 | if (write(socketfd, payload, *len) == -1) { | ||
54 | sway_abort("Unable to send IPC payload"); | ||
55 | } | ||
56 | 45 | ||
57 | size_t total = 0; | 46 | size_t total = 0; |
58 | while (total < ipc_header_size) { | 47 | while (total < ipc_header_size) { |
@@ -77,3 +66,21 @@ char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint3 | |||
77 | 66 | ||
78 | return response; | 67 | return response; |
79 | } | 68 | } |
69 | |||
70 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { | ||
71 | char data[ipc_header_size]; | ||
72 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | ||
73 | memcpy(data, ipc_magic, sizeof(ipc_magic)); | ||
74 | data32[0] = *len; | ||
75 | data32[1] = type; | ||
76 | |||
77 | if (write(socketfd, data, ipc_header_size) == -1) { | ||
78 | sway_abort("Unable to send IPC header"); | ||
79 | } | ||
80 | |||
81 | if (write(socketfd, payload, *len) == -1) { | ||
82 | sway_abort("Unable to send IPC payload"); | ||
83 | } | ||
84 | |||
85 | return ipc_recv_response(socketfd, len); | ||
86 | } | ||