2011-10-02 19:33:10 +02:00
|
|
|
|
/*
|
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
|
*
|
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
2015-04-04 02:17:56 +02:00
|
|
|
|
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
|
2011-10-02 19:33:10 +02:00
|
|
|
|
*
|
|
|
|
|
*/
|
2016-10-11 09:13:35 +02:00
|
|
|
|
#include "libi3.h"
|
|
|
|
|
|
2011-10-02 19:33:10 +02:00
|
|
|
|
#include <i3/ipc.h>
|
2020-04-19 09:43:48 +02:00
|
|
|
|
#include <stdint.h>
|
2011-10-02 19:33:10 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Formats a message (payload) of the given size and type and sends it to i3 via
|
|
|
|
|
* the given socket file descriptor.
|
|
|
|
|
*
|
|
|
|
|
* Returns -1 when write() fails, errno will remain.
|
|
|
|
|
* Returns 0 on success.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2020-05-10 01:33:55 +02:00
|
|
|
|
int ipc_send_message(int sockfd, const uint32_t message_size, const uint8_t *payload) {
|
2013-01-11 19:09:41 +01:00
|
|
|
|
const i3_ipc_header_t header = {
|
|
|
|
|
/* We don’t use I3_IPC_MAGIC because it’s a 0-terminated C string. */
|
2014-06-15 19:07:02 +02:00
|
|
|
|
.magic = {'i', '3', '-', 'i', 'p', 'c'},
|
2020-05-10 01:33:55 +02:00
|
|
|
|
.size = message_size};
|
2011-10-02 19:33:10 +02:00
|
|
|
|
|
2015-03-24 13:57:06 +01:00
|
|
|
|
if (writeall(sockfd, ((void *)&header), sizeof(i3_ipc_header_t)) == -1)
|
|
|
|
|
return -1;
|
2013-01-11 19:09:41 +01:00
|
|
|
|
|
2015-03-24 13:57:06 +01:00
|
|
|
|
if (writeall(sockfd, payload, message_size) == -1)
|
|
|
|
|
return -1;
|
2011-10-02 19:33:10 +02:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|