Move ipc_send_message and ipc_recv_message to libi3

Make i3-msg and src/ipc.c use it
This commit is contained in:
Michael Stapelberg
2011-10-02 18:33:10 +01:00
parent ff86852453
commit 046cf99585
5 changed files with 179 additions and 118 deletions

View File

@ -42,4 +42,29 @@ void *srealloc(void *ptr, size_t size);
*/
char *sstrdup(const char *str);
/**
* 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.
*
*/
int ipc_send_message(int sockfd, uint32_t message_size,
uint32_t message_type, const uint8_t *payload);
/**
* Reads a message from the given socket file descriptor and stores its length
* (reply_length) as well as a pointer to its contents (reply).
*
* Returns -1 when read() fails, errno will remain.
* Returns -2 when the IPC protocol is violated (invalid magic, unexpected
* message type, EOF instead of a message). Additionally, the error will be
* printed to stderr.
* Returns 0 on success.
*
*/
int ipc_recv_message(int sockfd, uint32_t message_type,
uint32_t *reply_length, uint8_t **reply);
#endif