2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
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, const uint32_t message_size,
28 const uint32_t message_type, const uint8_t *payload) {
29 const i3_ipc_header_t header = {
30 /* We don’t use I3_IPC_MAGIC because it’s a 0-terminated C string. */
31 .magic = { 'i', '3', '-', 'i', 'p', 'c' },
39 /* This first loop is basically unnecessary. No operating system has
40 * buffers which cannot fit 14 bytes into them, so the write() will only be
42 while (sent_bytes < sizeof(i3_ipc_header_t)) {
43 if ((n = write(sockfd, ((void*)&header) + sent_bytes, sizeof(i3_ipc_header_t) - sent_bytes)) == -1) {
54 while (sent_bytes < message_size) {
55 if ((n = write(sockfd, payload + sent_bytes, message_size - sent_bytes)) == -1) {