2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
6 * © 2009-2011 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
20 * Formats a message (payload) of the given size and type and sends it to i3 via
21 * the given socket file descriptor.
23 * Returns -1 when write() fails, errno will remain.
24 * Returns 0 on success.
27 int ipc_send_message(int sockfd, uint32_t message_size,
28 uint32_t message_type, const uint8_t *payload) {
29 int buffer_size = strlen(I3_IPC_MAGIC) + sizeof(uint32_t) + sizeof(uint32_t) + message_size;
30 char msg[buffer_size];
33 strncpy(walk, I3_IPC_MAGIC, buffer_size - 1);
34 walk += strlen(I3_IPC_MAGIC);
35 memcpy(walk, &message_size, sizeof(uint32_t));
36 walk += sizeof(uint32_t);
37 memcpy(walk, &message_type, sizeof(uint32_t));
38 walk += sizeof(uint32_t);
39 memcpy(walk, payload, message_size);
42 int bytes_to_go = buffer_size;
43 while (sent_bytes < bytes_to_go) {
44 int n = write(sockfd, msg + sent_bytes, bytes_to_go);