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

42 lines
1.2 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-12 01:59:56 +02:00
unsigned int length;
2018-10-04 01:54:12 +02:00
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-11 01:09:21 +02:00
int ipc_message_format (struct ipc_message *m, char type, const char *payload, ssize_t length);
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