2018-10-03 21:52:11 +02:00
|
|
|
#ifndef __IPC_USOCKET_H__
|
|
|
|
#define __IPC_USOCKET_H__
|
2016-12-17 18:00:04 +01:00
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
2018-11-02 21:03:54 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-12-18 00:54:43 +01:00
|
|
|
#define LISTEN_BACKLOG 128
|
|
|
|
|
2018-10-29 08:48:07 +01:00
|
|
|
#define RUNDIR "/run/ipc/"
|
2018-10-08 15:18:56 +02:00
|
|
|
#define PATH_MAX 4096
|
|
|
|
|
2018-10-12 01:59:56 +02:00
|
|
|
#define IPC_HEADER_SIZE 5
|
|
|
|
#define IPC_MAX_MESSAGE_SIZE 8000000-IPC_HEADER_SIZE
|
|
|
|
|
2018-10-08 15:18:56 +02:00
|
|
|
struct ipc_service {
|
2018-11-02 21:03:54 +01:00
|
|
|
uint32_t version;
|
|
|
|
uint32_t index;
|
2018-10-08 15:18:56 +02:00
|
|
|
char spath[PATH_MAX];
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t service_fd;
|
2018-10-08 15:18:56 +02:00
|
|
|
};
|
|
|
|
|
2018-10-10 23:08:58 +02:00
|
|
|
struct ipc_services {
|
|
|
|
struct ipc_service ** services;
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t size;
|
2018-10-10 23:08:58 +02:00
|
|
|
};
|
|
|
|
|
2018-10-08 15:18:56 +02:00
|
|
|
/**
|
|
|
|
* for all functions: 0 ok, < 0 not ok
|
|
|
|
*/
|
|
|
|
|
|
|
|
// input: len = max buf size
|
|
|
|
// output: *sent = nb received bytes
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t usock_send (const int32_t fd, const char *buf, ssize_t len, ssize_t *sent);
|
2018-10-08 15:18:56 +02:00
|
|
|
|
|
|
|
// -1 on msize == NULL or buf == NULL
|
|
|
|
// -1 on unsupported errors from read(2)
|
|
|
|
// exit on most errors from read(2)
|
|
|
|
//
|
|
|
|
// allocation of *len bytes on *buf == NULL
|
|
|
|
//
|
|
|
|
// output: *len = nb sent bytes
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t usock_recv (int32_t fd, char **buf, ssize_t *len);
|
2018-10-08 15:18:56 +02:00
|
|
|
|
|
|
|
// -1 on close(2) < 0
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t usock_close (int32_t fd);
|
2016-12-17 18:00:04 +01:00
|
|
|
|
|
|
|
// same as connect(2)
|
2018-10-08 15:18:56 +02:00
|
|
|
// -1 on fd == NULL
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t usock_connect (int32_t *fd, const char *path);
|
2016-12-18 00:54:43 +01:00
|
|
|
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t usock_init (int32_t *fd, const char *path);
|
2016-12-18 00:54:43 +01:00
|
|
|
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t usock_accept (int32_t fd, int32_t *pfd);
|
2016-12-18 00:54:43 +01:00
|
|
|
|
|
|
|
// same as unlink(2)
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t usock_remove (const char *path);
|
2016-12-17 18:00:04 +01:00
|
|
|
|
2018-11-02 21:03:54 +01:00
|
|
|
static inline int32_t ipc_service_empty (struct ipc_service *srv) { srv = srv; return 0 ;};
|
2018-10-08 16:15:35 +02:00
|
|
|
|
2018-10-10 23:08:58 +02:00
|
|
|
|
|
|
|
// store and remove only pointers on allocated structures
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t ipc_service_add (struct ipc_services *, struct ipc_service *);
|
|
|
|
int32_t ipc_service_del (struct ipc_services *, struct ipc_service *);
|
2018-10-10 23:08:58 +02:00
|
|
|
|
|
|
|
void ipc_services_print (struct ipc_services *);
|
|
|
|
void ipc_services_free (struct ipc_services *);
|
|
|
|
|
|
|
|
struct ipc_service * ipc_client_server_copy (const struct ipc_service *p);
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t ipc_service_eq (const struct ipc_service *p1, const struct ipc_service *p2);
|
2018-10-10 23:08:58 +02:00
|
|
|
// create the client service structure
|
|
|
|
void ipc_client_server_gen (struct ipc_service *p
|
2018-11-02 21:03:54 +01:00
|
|
|
, uint32_t index, uint32_t version);
|
2018-10-10 23:08:58 +02:00
|
|
|
|
|
|
|
void service_print (struct ipc_service *);
|
|
|
|
|
2016-12-17 18:00:04 +01:00
|
|
|
#endif
|