2018-10-03 21:52:11 +02:00
|
|
|
#ifndef __IPC_MSG_H__
|
|
|
|
#define __IPC_MSG_H__
|
2016-12-21 01:26:47 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-10-08 15:18:56 +02:00
|
|
|
// FIXME, removed messages types: MSG_TYPE_CON, MSG_TYPE_CLOSE, MSG_TYPE_ACK
|
|
|
|
// this implies an underlying communication that is always correctly handled by the system
|
|
|
|
// (currently: unix sockets)
|
|
|
|
|
|
|
|
#define MSG_TYPE_SERVER_CLOSE 0
|
|
|
|
#define MSG_TYPE_ERR 1
|
|
|
|
#define MSG_TYPE_DATA 2
|
2016-12-21 01:26:47 +01:00
|
|
|
|
2018-10-03 22:02:37 +02:00
|
|
|
struct ipc_message {
|
2016-12-21 01:26:47 +01:00
|
|
|
char type;
|
2018-10-04 01:54:12 +02:00
|
|
|
unsigned short length;
|
|
|
|
char *payload;
|
2016-12-21 01:26:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// used to create msg structure from buffer
|
2018-10-08 16:15:35 +02:00
|
|
|
int ipc_message_format_read (struct ipc_message *m, const char *buf, ssize_t msize);
|
2016-12-21 01:26:47 +01:00
|
|
|
// used to create buffer from msg structure
|
2018-10-08 16:15:35 +02:00
|
|
|
int ipc_message_format_write (const struct ipc_message *m, char **buf, ssize_t *msize);
|
2016-12-21 01:26:47 +01:00
|
|
|
|
|
|
|
// read a structure msg from fd
|
2018-10-08 15:18:56 +02:00
|
|
|
// 1 on a recipient socket close
|
2018-10-03 22:02:37 +02:00
|
|
|
int ipc_message_read (int fd, struct ipc_message *m);
|
2016-12-21 01:26:47 +01:00
|
|
|
// write a structure msg to fd
|
2018-10-03 22:02:37 +02:00
|
|
|
int ipc_message_write (int fd, const struct ipc_message *m);
|
2016-12-21 01:26:47 +01:00
|
|
|
|
2018-10-08 16:15:35 +02:00
|
|
|
int ipc_message_format_data (struct ipc_message *m, const char *payload, ssize_t length);
|
2018-10-04 22:51:31 +02:00
|
|
|
int ipc_message_format_server_close (struct ipc_message *m);
|
2016-12-21 01:26:47 +01:00
|
|
|
|
2018-10-08 15:18:56 +02:00
|
|
|
int ipc_message_empty (struct ipc_message *m);
|
2018-10-03 22:02:37 +02:00
|
|
|
void ipc_message_print (const struct ipc_message *m);
|
2016-12-21 01:26:47 +01:00
|
|
|
|
|
|
|
#endif
|