Obsolete
/
libipc-old
Archived
3
0
Fork 0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues/pull-requests.
libipc-old/core/message.h

41 lines
1.1 KiB
C
Raw Normal View History

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-09 03:09:45 +02:00
// the underlying communication must always correctly handled by the system
2018-10-08 15:18:56 +02:00
// (currently: unix sockets)
2018-10-09 03:09:45 +02:00
enum msg_types {
MSG_TYPE_SERVER_CLOSE = 0
, MSG_TYPE_ERR
, MSG_TYPE_DATA
} message_types;
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);
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