uint32_t, uint8, int32_t, int8_t

more_to_read
Philippe PITTOLI 2018-11-02 21:03:54 +01:00
parent be783e69b1
commit d4caca0fe9
22 changed files with 207 additions and 195 deletions

View File

@ -17,20 +17,20 @@ struct ipc_client * ipc_server_client_copy (const struct ipc_client *p)
return copy;
}
int ipc_server_client_eq (const struct ipc_client *p1, const struct ipc_client *p2)
int32_t ipc_server_client_eq (const struct ipc_client *p1, const struct ipc_client *p2)
{
return (p1->version == p2->version && p1->index == p2->index
&& p1->proc_fd == p2->proc_fd);
}
void ipc_server_client_gen (struct ipc_client *p
, unsigned int index, unsigned int version)
, uint32_t index, uint32_t version)
{
p->version = version;
p->index = index;
}
int ipc_client_add (struct ipc_clients *clients, struct ipc_client *p)
int32_t ipc_client_add (struct ipc_clients *clients, struct ipc_client *p)
{
assert(clients != NULL);
assert(p != NULL);
@ -47,7 +47,7 @@ int ipc_client_add (struct ipc_clients *clients, struct ipc_client *p)
return 0;
}
int ipc_client_del (struct ipc_clients *clients, struct ipc_client *p)
int32_t ipc_client_del (struct ipc_clients *clients, struct ipc_client *p)
{
assert(clients != NULL);
assert(p != NULL);
@ -56,7 +56,7 @@ int ipc_client_del (struct ipc_clients *clients, struct ipc_client *p)
return -1;
}
int i;
int32_t i;
for (i = 0; i < clients->size; i++) {
if (clients->clients[i] == p) {
@ -90,7 +90,7 @@ void client_print (struct ipc_client *p)
void ipc_clients_print (struct ipc_clients *ap)
{
int i;
int32_t i;
for (i = 0; i < ap->size; i++) {
printf("%d : ", i);
client_print(ap->clients[i]);

View File

@ -1,29 +1,31 @@
#ifndef __IPC_CLIENT_H__
#define __IPC_CLIENT_H__
#include <stdint.h>
struct ipc_client {
unsigned int version;
unsigned int index;
int proc_fd;
uint32_t version;
uint32_t index;
int32_t proc_fd;
};
struct ipc_clients {
struct ipc_client **clients;
int size;
int32_t size;
};
// store and remove only pointers on allocated structures
int ipc_client_add (struct ipc_clients *, struct ipc_client *);
int ipc_client_del (struct ipc_clients *, struct ipc_client *);
int32_t ipc_client_add (struct ipc_clients *, struct ipc_client *);
int32_t ipc_client_del (struct ipc_clients *, struct ipc_client *);
void ipc_clients_print (struct ipc_clients *);
void ipc_clients_free (struct ipc_clients *);
struct ipc_client * ipc_server_client_copy (const struct ipc_client *p);
int ipc_server_client_eq (const struct ipc_client *p1, const struct ipc_client *p2);
int32_t ipc_server_client_eq (const struct ipc_client *p1, const struct ipc_client *p2);
// create the service client structure
void ipc_server_client_gen (struct ipc_client *p
, unsigned int index, unsigned int version);
, uint32_t index, uint32_t version);
void client_print (struct ipc_client *);
#endif

View File

@ -8,7 +8,7 @@
#include <stdio.h>
#include <errno.h>
void service_path (char *path, const char *sname, int index, int version)
void service_path (char *path, const char *sname, int32_t index, int32_t version)
{
assert (path != NULL);
assert (sname != NULL);
@ -16,7 +16,7 @@ void service_path (char *path, const char *sname, int index, int version)
snprintf (path, PATH_MAX, "%s/%s-%d-%d", RUNDIR, sname, index, version);
}
int ipc_server_init (char **env
int32_t ipc_server_init (char **env
, struct ipc_service *srv, const char *sname)
{
if (srv == NULL)
@ -33,7 +33,7 @@ int ipc_server_init (char **env
// gets the service path
service_path (srv->spath, sname, srv->index, srv->version);
int ret = usock_init (&srv->service_fd, srv->spath);
int32_t ret = usock_init (&srv->service_fd, srv->spath);
if (ret < 0) {
handle_err ("ipc_server_init", "usock_init ret < 0");
return -1;
@ -42,12 +42,12 @@ int ipc_server_init (char **env
return 0;
}
int ipc_server_accept (struct ipc_service *srv, struct ipc_client *p)
int32_t ipc_server_accept (struct ipc_service *srv, struct ipc_client *p)
{
assert (srv != NULL);
assert (p != NULL);
int ret = usock_accept (srv->service_fd, &p->proc_fd);
int32_t ret = usock_accept (srv->service_fd, &p->proc_fd);
if (ret < 0) {
handle_err ("ipc_server_accept", "usock_accept < 0");
return -1;
@ -57,30 +57,30 @@ int ipc_server_accept (struct ipc_service *srv, struct ipc_client *p)
}
// empty the srv structure
int ipc_server_close (struct ipc_service *srv)
int32_t ipc_server_close (struct ipc_service *srv)
{
usock_close (srv->service_fd);
int ret = usock_remove (srv->spath);
int32_t ret = usock_remove (srv->spath);
ipc_service_empty (srv);
return ret;
}
int ipc_server_close_client (struct ipc_client *p)
int32_t ipc_server_close_client (struct ipc_client *p)
{
return usock_close (p->proc_fd);
}
int ipc_server_read (const struct ipc_client *p, struct ipc_message *m)
int32_t ipc_server_read (const struct ipc_client *p, struct ipc_message *m)
{
return ipc_message_read (p->proc_fd, m);
}
int ipc_server_write (const struct ipc_client *p, const struct ipc_message *m)
int32_t ipc_server_write (const struct ipc_client *p, const struct ipc_message *m)
{
return ipc_message_write (p->proc_fd, m);
}
int ipc_application_connection (char **env
int32_t ipc_application_connection (char **env
, struct ipc_service *srv, const char *sname)
{
// TODO
@ -101,7 +101,7 @@ int ipc_application_connection (char **env
// gets the service path
service_path (srv->spath, sname, srv->index, srv->version);
int ret = usock_connect (&srv->service_fd, srv->spath);
int32_t ret = usock_connect (&srv->service_fd, srv->spath);
if (ret < 0) {
handle_err ("ipc_application_connection", "usock_connect ret <= 0");
return -1;
@ -111,27 +111,27 @@ int ipc_application_connection (char **env
}
// close the socket
int ipc_application_close (struct ipc_service *srv)
int32_t ipc_application_close (struct ipc_service *srv)
{
return usock_close (srv->service_fd);
}
int ipc_application_read (struct ipc_service *srv, struct ipc_message *m)
int32_t ipc_application_read (struct ipc_service *srv, struct ipc_message *m)
{
return ipc_message_read (srv->service_fd, m);
}
int ipc_application_write (struct ipc_service *srv, const struct ipc_message *m)
int32_t ipc_application_write (struct ipc_service *srv, const struct ipc_message *m)
{
return ipc_message_write (srv->service_fd, m);
}
/*calculer le max filedescriptor*/
static int get_max_fd_from_ipc_clients_ (struct ipc_clients *clients)
static int32_t get_max_fd_from_ipc_clients_ (struct ipc_clients *clients)
{
int i;
int max = 0;
int32_t i;
int32_t max = 0;
for (i = 0; i < clients->size; i++ ) {
if (clients->clients[i]->proc_fd > max) {
@ -142,10 +142,10 @@ static int get_max_fd_from_ipc_clients_ (struct ipc_clients *clients)
return max;
}
static int get_max_fd_from_ipc_services_ (struct ipc_services *services)
static int32_t get_max_fd_from_ipc_services_ (struct ipc_services *services)
{
int i;
int max = 0;
int32_t i;
int32_t max = 0;
for (i = 0; i < services->size; i++ ) {
if (services->services[i]->service_fd > max) {
@ -166,8 +166,8 @@ static int get_max_fd_from_ipc_services_ (struct ipc_services *services)
* -1 = error
*/
int ipc_server_select (struct ipc_clients *clients, struct ipc_service *srv
, struct ipc_clients *active_clients, int *new_connection)
int32_t ipc_server_select (struct ipc_clients *clients, struct ipc_service *srv
, struct ipc_clients *active_clients, int32_t *new_connection)
{
*new_connection = 0;
assert (clients != NULL);
@ -176,15 +176,15 @@ int ipc_server_select (struct ipc_clients *clients, struct ipc_service *srv
// delete previous read active_clients array
ipc_clients_free (active_clients);
int i, j;
int32_t i, j;
/* master file descriptor list */
fd_set master;
fd_set readf;
/* maximum file descriptor number */
int fdmax;
int32_t fdmax;
/* listening socket descriptor */
int listener = srv->service_fd;
int32_t listener = srv->service_fd;
/* clear the master and temp sets */
FD_ZERO(&master);
@ -232,7 +232,7 @@ int ipc_server_select (struct ipc_clients *clients, struct ipc_service *srv
* -1 = error
*/
int ipc_application_select (struct ipc_services *services, struct ipc_services *active_services)
int32_t ipc_application_select (struct ipc_services *services, struct ipc_services *active_services)
{
assert (services != NULL);
assert (active_services != NULL);
@ -240,13 +240,13 @@ int ipc_application_select (struct ipc_services *services, struct ipc_services *
// delete previous read active_services array
ipc_services_free (active_services);
int i, j;
int32_t i, j;
/* master file descriptor list */
fd_set master;
fd_set readf;
/* maximum file descriptor number */
int fdmax;
int32_t fdmax;
/* clear the master and temp sets */
FD_ZERO(&master);
@ -278,7 +278,7 @@ int ipc_application_select (struct ipc_services *services, struct ipc_services *
return 0;
}
int handle_new_connection (struct ipc_service *srv
int32_t handle_new_connection (struct ipc_service *srv
, struct ipc_clients *clients
, struct ipc_client **new_client)
{
@ -300,22 +300,22 @@ int handle_new_connection (struct ipc_service *srv
return 0;
}
int ipc_service_poll_event (struct ipc_clients *clients, struct ipc_service *srv
int32_t ipc_service_poll_event (struct ipc_clients *clients, struct ipc_service *srv
, struct ipc_event *event)
{
assert (clients != NULL);
IPC_EVENT_CLEAN(event);
int i, j;
int32_t i, j;
/* master file descriptor list */
fd_set master;
fd_set readf;
/* maximum file descriptor number */
int fdmax;
int32_t fdmax;
/* listening socket descriptor */
int listener = srv->service_fd;
int32_t listener = srv->service_fd;
/* clear the master and temp sets */
FD_ZERO(&master);
@ -349,7 +349,7 @@ int ipc_service_poll_event (struct ipc_clients *clients, struct ipc_service *srv
if(i == clients->clients[j]->proc_fd ) {
// listen to what they have to say (disconnection or message)
// then add a client to `event`, the ipc_event structure
int ret = 0;
int32_t ret = 0;
struct ipc_message *m = NULL;
m = malloc (sizeof(struct ipc_message));
if (m == NULL) {
@ -398,19 +398,19 @@ int ipc_service_poll_event (struct ipc_clients *clients, struct ipc_service *srv
return 0;
}
int ipc_application_poll_event_ (struct ipc_services *services, struct ipc_event *event, int interactive)
int32_t ipc_application_poll_event_ (struct ipc_services *services, struct ipc_event *event, int32_t interactive)
{
assert (services != NULL);
IPC_EVENT_CLEAN(event);
int i, j;
int32_t i, j;
/* master file descriptor list */
fd_set master;
fd_set readf;
/* maximum file descriptor number */
int fdmax;
int32_t fdmax;
/* clear the master and temp sets */
FD_ZERO(&master);
@ -455,7 +455,7 @@ int ipc_application_poll_event_ (struct ipc_services *services, struct ipc_event
if(i == services->services[j]->service_fd ) {
// listen to what they have to say (disconnection or message)
// then add a client to `event`, the ipc_event structure
int ret = 0;
int32_t ret = 0;
struct ipc_message *m = NULL;
m = malloc (sizeof(struct ipc_message));
if (m == NULL) {
@ -504,10 +504,10 @@ int ipc_application_poll_event_ (struct ipc_services *services, struct ipc_event
return 0;
}
int ipc_application_poll_event (struct ipc_services *services, struct ipc_event *event) {
int32_t ipc_application_poll_event (struct ipc_services *services, struct ipc_event *event) {
return ipc_application_poll_event_ (services, event, 0);
}
int ipc_application_peek_event (struct ipc_services *services, struct ipc_event *event) {
int32_t ipc_application_peek_event (struct ipc_services *services, struct ipc_event *event) {
return ipc_application_poll_event_ (services, event, 1);
}

View File

@ -20,20 +20,20 @@
// srv->version and srv->index must be already set
// init unix socket + fill srv->spath
int ipc_server_init (char **env
int32_t ipc_server_init (char **env
, struct ipc_service *srv, const char *sname);
int ipc_server_close (struct ipc_service *srv);
int ipc_server_close_client (struct ipc_client *p);
int ipc_server_accept (struct ipc_service *srv, struct ipc_client *p);
int32_t ipc_server_close (struct ipc_service *srv);
int32_t ipc_server_close_client (struct ipc_client *p);
int32_t ipc_server_accept (struct ipc_service *srv, struct ipc_client *p);
// 1 on a recipient socket close
int ipc_server_read (const struct ipc_client *, struct ipc_message *m);
int ipc_server_write (const struct ipc_client *, const struct ipc_message *m);
int32_t ipc_server_read (const struct ipc_client *, struct ipc_message *m);
int32_t ipc_server_write (const struct ipc_client *, const struct ipc_message *m);
int ipc_server_select (struct ipc_clients * clients, struct ipc_service *srv
, struct ipc_clients *active_clients, int *new_connection);
int32_t ipc_server_select (struct ipc_clients * clients, struct ipc_service *srv
, struct ipc_clients *active_clients, int32_t *new_connection);
int ipc_service_poll_event (struct ipc_clients *clients, struct ipc_service *srv
int32_t ipc_service_poll_event (struct ipc_clients *clients, struct ipc_service *srv
, struct ipc_event *event);
// APPLICATION
@ -41,17 +41,17 @@ int ipc_service_poll_event (struct ipc_clients *clients, struct ipc_service *srv
// Initialize connection with unix socket
// send the connection string to $TMP/<service>
// fill srv->spath && srv->service_fd
int ipc_application_connection (char **env
int32_t ipc_application_connection (char **env
, struct ipc_service *, const char *);
int ipc_application_close (struct ipc_service *);
int32_t ipc_application_close (struct ipc_service *);
// 1 on a recipient socket close
int ipc_application_read (struct ipc_service *srv, struct ipc_message *m);
int ipc_application_write (struct ipc_service *, const struct ipc_message *m);
int32_t ipc_application_read (struct ipc_service *srv, struct ipc_message *m);
int32_t ipc_application_write (struct ipc_service *, const struct ipc_message *m);
int ipc_application_select (struct ipc_services *services, struct ipc_services *active_services);
int32_t ipc_application_select (struct ipc_services *services, struct ipc_services *active_services);
int ipc_application_poll_event (struct ipc_services *services, struct ipc_event *event);
int ipc_application_peek_event (struct ipc_services *services, struct ipc_event *event);
int32_t ipc_application_poll_event (struct ipc_services *services, struct ipc_event *event);
int32_t ipc_application_peek_event (struct ipc_services *services, struct ipc_event *event);
#endif

View File

@ -1,6 +1,8 @@
#ifndef __IPC_H__
#define __IPC_H__
#include <stdint.h>
#include "client.h"
#include "communication.h"
#include "error.h"

View File

@ -12,7 +12,7 @@ void ipc_message_print (const struct ipc_message *m)
#endif
}
int ipc_message_format_read (struct ipc_message *m, const char *buf, ssize_t msize)
int32_t ipc_message_format_read (struct ipc_message *m, const char *buf, ssize_t msize)
{
assert (m != NULL);
assert (buf != NULL);
@ -43,7 +43,7 @@ int ipc_message_format_read (struct ipc_message *m, const char *buf, ssize_t msi
return 0;
}
int ipc_message_format_write (const struct ipc_message *m, char **buf, ssize_t *msize)
int32_t ipc_message_format_write (const struct ipc_message *m, char **buf, ssize_t *msize)
{
assert (m != NULL);
assert (buf != NULL);
@ -82,14 +82,14 @@ int ipc_message_format_write (const struct ipc_message *m, char **buf, ssize_t *
}
// 1 on a recipient socket close
int ipc_message_read (int fd, struct ipc_message *m)
int32_t ipc_message_read (int32_t fd, struct ipc_message *m)
{
assert (m != NULL);
char *buf = NULL;
ssize_t msize = IPC_MAX_MESSAGE_SIZE;
int ret = usock_recv (fd, &buf, &msize);
int32_t ret = usock_recv (fd, &buf, &msize);
if (ret < 0) {
// on error, buffer already freed
handle_err ("msg_read", "usock_recv");
@ -109,7 +109,7 @@ int ipc_message_read (int fd, struct ipc_message *m)
return 0;
}
int ipc_message_write (int fd, const struct ipc_message *m)
int32_t ipc_message_write (int32_t fd, const struct ipc_message *m)
{
assert (m != NULL);
@ -118,7 +118,7 @@ int ipc_message_write (int fd, const struct ipc_message *m)
ipc_message_format_write (m, &buf, &msize);
ssize_t nbytes_sent = 0;
int ret = usock_send (fd, buf, msize, &nbytes_sent);
int32_t ret = usock_send (fd, buf, msize, &nbytes_sent);
if (ret < 0) {
if (buf != NULL) {
free (buf);
@ -145,7 +145,7 @@ int ipc_message_write (int fd, const struct ipc_message *m)
// MSG FORMAT
int ipc_message_format (struct ipc_message *m, char type, const char *payload, ssize_t length)
int32_t ipc_message_format (struct ipc_message *m, char type, const char *payload, ssize_t length)
{
assert (m != NULL);
assert (length <= IPC_MAX_MESSAGE_SIZE);
@ -157,7 +157,7 @@ int ipc_message_format (struct ipc_message *m, char type, const char *payload, s
}
m->type = type;
m->length = (unsigned int) length;
m->length = (uint32_t) length;
if (payload != NULL) {
if (m->payload != NULL) {
@ -177,17 +177,17 @@ int ipc_message_format (struct ipc_message *m, char type, const char *payload, s
return 0;
}
int ipc_message_format_data (struct ipc_message *m, const char *payload, ssize_t length)
int32_t ipc_message_format_data (struct ipc_message *m, const char *payload, ssize_t length)
{
return ipc_message_format (m, MSG_TYPE_DATA, payload, length);
}
int ipc_message_format_server_close (struct ipc_message *m)
int32_t ipc_message_format_server_close (struct ipc_message *m)
{
return ipc_message_format (m, MSG_TYPE_SERVER_CLOSE, NULL, 0);
}
int ipc_message_empty (struct ipc_message *m)
int32_t ipc_message_empty (struct ipc_message *m)
{
assert (m != NULL);

View File

@ -5,6 +5,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
// the underlying communication must always correctly handled by the system
// (currently: unix sockets)
@ -16,26 +18,26 @@ enum msg_types {
struct ipc_message {
char type;
unsigned int length;
uint32_t length;
char *payload;
};
// used to create msg structure from buffer
int ipc_message_format_read (struct ipc_message *m, const char *buf, ssize_t msize);
int32_t ipc_message_format_read (struct ipc_message *m, const char *buf, ssize_t msize);
// used to create buffer from msg structure
int ipc_message_format_write (const struct ipc_message *m, char **buf, ssize_t *msize);
int32_t ipc_message_format_write (const struct ipc_message *m, char **buf, ssize_t *msize);
// read a structure msg from fd
// 1 on a recipient socket close
int ipc_message_read (int fd, struct ipc_message *m);
int32_t ipc_message_read (int32_t fd, struct ipc_message *m);
// write a structure msg to fd
int ipc_message_write (int fd, const struct ipc_message *m);
int32_t ipc_message_write (int32_t fd, const struct ipc_message *m);
int ipc_message_format (struct ipc_message *m, char type, const char *payload, ssize_t length);
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);
int32_t ipc_message_format (struct ipc_message *m, char type, const char *payload, ssize_t length);
int32_t ipc_message_format_data (struct ipc_message *m, const char *payload, ssize_t length);
int32_t ipc_message_format_server_close (struct ipc_message *m);
int ipc_message_empty (struct ipc_message *m);
int32_t ipc_message_empty (struct ipc_message *m);
void ipc_message_print (const struct ipc_message *m);
#endif

View File

@ -8,7 +8,7 @@
#include <unistd.h>
#include <assert.h>
int usock_send (const int fd, const char *buf, ssize_t len, ssize_t *sent)
int32_t usock_send (const int32_t fd, const char *buf, ssize_t len, ssize_t *sent)
{
ssize_t ret = 0;
ret = send (fd, buf, len, MSG_NOSIGNAL);
@ -21,7 +21,7 @@ int usock_send (const int fd, const char *buf, ssize_t len, ssize_t *sent)
}
// *len is changed to the total message size read (header + payload)
int usock_recv (const int fd, char **buf, ssize_t *len)
int32_t usock_recv (const int32_t fd, char **buf, ssize_t *len)
{
assert(buf != NULL);
assert(len != NULL);
@ -47,8 +47,8 @@ int usock_recv (const int fd, char **buf, ssize_t *len)
*buf = malloc (*len + IPC_HEADER_SIZE);
}
unsigned int msize = 0;
unsigned int msize_read = 0;
uint32_t msize = 0;
uint32_t msize_read = 0;
do {
ret = recv (fd, *buf, *len, 0);
@ -135,12 +135,12 @@ int usock_recv (const int fd, char **buf, ssize_t *len)
return 1;
}
// print_hexa ("msg recv", (unsigned char *)*buf, *len);
// print_hexa ("msg recv", (uint8_t *)*buf, *len);
// fflush(stdout);
return 0;
}
int usock_connect (int *fd, const char *path)
int32_t usock_connect (int32_t *fd, const char *path)
{
assert (fd != NULL);
assert (path != NULL);
@ -155,7 +155,7 @@ int usock_connect (int *fd, const char *path)
return -1;
}
int sfd;
int32_t sfd;
struct sockaddr_un my_addr;
socklen_t peer_addr_size;
@ -183,7 +183,7 @@ int usock_connect (int *fd, const char *path)
return 0;
}
int usock_init (int *fd, const char *path)
int32_t usock_init (int32_t *fd, const char *path)
{
assert (fd != NULL);
assert (path != NULL);
@ -198,7 +198,7 @@ int usock_init (int *fd, const char *path)
return -1;
}
int sfd;
int32_t sfd;
struct sockaddr_un my_addr;
socklen_t peer_addr_size;
@ -236,7 +236,7 @@ int usock_init (int *fd, const char *path)
return 0;
}
int usock_accept (int fd, int *pfd)
int32_t usock_accept (int32_t fd, int32_t *pfd)
{
assert (pfd != NULL);
@ -259,9 +259,9 @@ int usock_accept (int fd, int *pfd)
return 0;
}
int usock_close (int fd)
int32_t usock_close (int32_t fd)
{
int ret = 0;
int32_t ret = 0;
ret = close (fd);
if (ret < 0) {
@ -272,7 +272,7 @@ int usock_close (int fd)
return 0;
}
int usock_remove (const char *path)
int32_t usock_remove (const char *path)
{
return unlink (path);
}
@ -292,20 +292,20 @@ struct ipc_service * ipc_client_server_copy (const struct ipc_service *p)
return copy;
}
int ipc_client_server_eq (const struct ipc_service *p1, const struct ipc_service *p2)
int32_t ipc_client_server_eq (const struct ipc_service *p1, const struct ipc_service *p2)
{
return (p1->version == p2->version && p1->index == p2->index
&& p1->service_fd == p2->service_fd && memcmp(p1->spath, p1->spath, PATH_MAX) == 0 );
}
void ipc_client_server_gen (struct ipc_service *p
, unsigned int index, unsigned int version)
, uint32_t index, uint32_t version)
{
p->version = version;
p->index = index;
}
int ipc_service_add (struct ipc_services *services, struct ipc_service *p)
int32_t ipc_service_add (struct ipc_services *services, struct ipc_service *p)
{
assert(services != NULL);
assert(p != NULL);
@ -322,7 +322,7 @@ int ipc_service_add (struct ipc_services *services, struct ipc_service *p)
return 0;
}
int ipc_service_del (struct ipc_services *services, struct ipc_service *p)
int32_t ipc_service_del (struct ipc_services *services, struct ipc_service *p)
{
assert(services != NULL);
assert(p != NULL);
@ -331,7 +331,7 @@ int ipc_service_del (struct ipc_services *services, struct ipc_service *p)
return -1;
}
int i;
int32_t i;
for (i = 0; i < services->size; i++) {
if (services->services[i] == p) {
@ -365,7 +365,7 @@ void service_print (struct ipc_service *p)
void ipc_services_print (struct ipc_services *ap)
{
int i;
int32_t i;
for (i = 0; i < ap->size; i++) {
printf("%d : ", i);
service_print(ap->services[i]);

View File

@ -5,6 +5,8 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <stdint.h>
#define LISTEN_BACKLOG 128
#define RUNDIR "/run/ipc/"
@ -14,15 +16,15 @@
#define IPC_MAX_MESSAGE_SIZE 8000000-IPC_HEADER_SIZE
struct ipc_service {
unsigned int version;
unsigned int index;
uint32_t version;
uint32_t index;
char spath[PATH_MAX];
int service_fd;
int32_t service_fd;
};
struct ipc_services {
struct ipc_service ** services;
int size;
int32_t size;
};
/**
@ -31,7 +33,7 @@ struct ipc_services {
// input: len = max buf size
// output: *sent = nb received bytes
int usock_send (const int fd, const char *buf, ssize_t len, ssize_t *sent);
int32_t usock_send (const int32_t fd, const char *buf, ssize_t len, ssize_t *sent);
// -1 on msize == NULL or buf == NULL
// -1 on unsupported errors from read(2)
@ -40,37 +42,37 @@ int usock_send (const int fd, const char *buf, ssize_t len, ssize_t *sent);
// allocation of *len bytes on *buf == NULL
//
// output: *len = nb sent bytes
int usock_recv (int fd, char **buf, ssize_t *len);
int32_t usock_recv (int32_t fd, char **buf, ssize_t *len);
// -1 on close(2) < 0
int usock_close (int fd);
int32_t usock_close (int32_t fd);
// same as connect(2)
// -1 on fd == NULL
int usock_connect (int *fd, const char *path);
int32_t usock_connect (int32_t *fd, const char *path);
int usock_init (int *fd, const char *path);
int32_t usock_init (int32_t *fd, const char *path);
int usock_accept (int fd, int *pfd);
int32_t usock_accept (int32_t fd, int32_t *pfd);
// same as unlink(2)
int usock_remove (const char *path);
int32_t usock_remove (const char *path);
static inline int ipc_service_empty (struct ipc_service *srv) { srv = srv; return 0 ;};
static inline int32_t ipc_service_empty (struct ipc_service *srv) { srv = srv; return 0 ;};
// store and remove only pointers on allocated structures
int ipc_service_add (struct ipc_services *, struct ipc_service *);
int ipc_service_del (struct ipc_services *, struct ipc_service *);
int32_t ipc_service_add (struct ipc_services *, struct ipc_service *);
int32_t ipc_service_del (struct ipc_services *, struct ipc_service *);
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);
int ipc_service_eq (const struct ipc_service *p1, const struct ipc_service *p2);
int32_t ipc_service_eq (const struct ipc_service *p1, const struct ipc_service *p2);
// create the client service structure
void ipc_client_server_gen (struct ipc_service *p
, unsigned int index, unsigned int version);
, uint32_t index, uint32_t version);
void service_print (struct ipc_service *);

View File

@ -1,6 +1,6 @@
#include "utils.h"
void print_hexa (const char *prefix, unsigned char *payload, size_t size)
void print_hexa (const char *prefix, uint8_t *payload, size_t size)
{
if (! payload)
return ;
@ -16,7 +16,7 @@ void print_hexa (const char *prefix, unsigned char *payload, size_t size)
}
void mprint_hexa (char *prefix, unsigned char *buf, size_t length)
void mprint_hexa (char *prefix, uint8_t *buf, size_t length)
{
print_hexa (prefix, buf, length);
}

View File

@ -5,7 +5,9 @@
#include <stdlib.h>
#include <string.h>
void print_hexa (const char *prefix, unsigned char *payload, size_t size);
void mprint_hexa (char *prefix, unsigned char *buf, size_t length);
#include <stdint.h>
void print_hexa (const char *prefix, uint8_t *payload, size_t size);
void mprint_hexa (char *prefix, uint8_t *buf, size_t length);
#endif

View File

@ -3,12 +3,12 @@
#define SERVICE "windowing"
void
ohshit(int rvalue, const char* str) {
ohshit(int32_t rvalue, const char* str) {
fprintf(stderr, "%s\n", str);
exit(rvalue);
}
int main(int argc, char * argv[], char *env[])
int32_t main(int32_t argc, char * argv[], char *env[])
{
struct ipc_service srv;
memset (&srv, 0, sizeof (struct ipc_service));
@ -26,8 +26,8 @@ int main(int argc, char * argv[], char *env[])
struct ipc_client p;
memset (&p, 0, sizeof (struct ipc_client));
int index = 0; // first time we communication with the service
int version = 1;
int32_t index = 0; // first time we communication with the service
int32_t version = 1;
printf ("app creation\n");
if (application_create (&p, index, version)) // called by the application

View File

@ -7,11 +7,11 @@ LIST_HEAD(mlist, node);
// elements structure of the list
struct node {
int content;
int32_t content;
LIST_ENTRY(node) entries;
};
int main(int argc, char * argv[])
int32_t main(int32_t argc, char * argv[])
{
(void) argc;
(void) argv;

View File

@ -8,7 +8,7 @@
#define PKT_ERROR 2
void
ohshit(int rvalue, const char* str) {
ohshit(int32_t rvalue, const char* str) {
fprintf (stderr, "\033[31merr: %s\033[00m\n", str);
exit (rvalue);
}
@ -21,15 +21,15 @@ void usage (char **argv)
printf ( " This sends a CBOR msg [ 1, \"data\" ]\n");
}
int
main(int argc, char **argv)
int32_t
main(int32_t argc, char **argv)
{
if (argc == 2 && strcmp ("-h", argv[1]) == 0) {
usage (argv);
exit (1);
}
unsigned char buf[BUFSIZ];
uint8_t buf[BUFSIZ];
memset (buf, 0, BUFSIZ);
ssize_t buflen = read (0, buf, BUFSIZ);
@ -42,7 +42,7 @@ main(int argc, char **argv)
.value = cbor_move(cbor_build_bytestring(buf, buflen))
});
/* Output: `length` bytes of data in the `buffer` */
unsigned char * buffer;
uint8_t * buffer;
size_t buffer_size, length = cbor_serialize_alloc (root, &buffer, &buffer_size);
fwrite(buffer, 1, length, stdout);

View File

@ -3,7 +3,7 @@
#include <string.h>
#include <unistd.h>
int main(int argc, char * argv[])
int32_t main(int32_t argc, char * argv[])
{
(void) argc;

View File

@ -3,7 +3,7 @@
#include <string.h>
#include <unistd.h>
int main(int argc, char * argv[])
int32_t main(int32_t argc, char * argv[])
{
(void) argc;
(void) argv;

View File

@ -64,7 +64,7 @@ void log_debug (const char* message, ...) {
}
static
int recvsockfd (int socket) // receive fd from socket
int32_t recvsockfd (int32_t socket) // receive fd from socket
{
struct ipc_messagehdr msg = {0};
@ -84,14 +84,14 @@ int recvsockfd (int socket) // receive fd from socket
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
printf ("About to extract fd\n");
int fd;
int32_t fd;
memmove(&fd, CMSG_DATA(cmsg), sizeof(fd));
printf ("Extracted fd %d\n", fd);
return fd;
}
int usock_connect (int *fd, const char *path)
int32_t usock_connect (int32_t *fd, const char *path)
{
assert (fd != NULL);
assert (path != NULL);
@ -106,7 +106,7 @@ int usock_connect (int *fd, const char *path)
return -1;
}
int sfd;
int32_t sfd;
struct sockaddr_un my_addr;
socklen_t peer_addr_size;
@ -134,7 +134,7 @@ int usock_connect (int *fd, const char *path)
return 0;
}
int usock_init (int *fd, const char *path)
int32_t usock_init (int32_t *fd, const char *path)
{
assert (fd != NULL);
assert (path != NULL);
@ -149,7 +149,7 @@ int usock_init (int *fd, const char *path)
return -1;
}
int sfd;
int32_t sfd;
struct sockaddr_un my_addr;
socklen_t peer_addr_size;
@ -187,7 +187,7 @@ int usock_init (int *fd, const char *path)
return 0;
}
int usock_accept (int fd, int *pfd)
int32_t usock_accept (int32_t fd, int32_t *pfd)
{
assert (pfd != NULL);
@ -210,9 +210,9 @@ int usock_accept (int fd, int *pfd)
return 0;
}
int usock_close (int fd)
int32_t usock_close (int32_t fd)
{
int ret;
int32_t ret;
ret = close (fd);
if (ret < 0) {
handle_err ("usock_close", "close ret < 0");
@ -221,15 +221,15 @@ int usock_close (int fd)
return ret;
}
int usock_remove (const char *path)
int32_t usock_remove (const char *path)
{
return unlink (path);
}
int main(int argc, char * argv[])
int32_t main(int32_t argc, char * argv[])
{
int tcpsockfd;
int usockfd;
int32_t tcpsockfd;
int32_t usockfd;
// check the number of args on command line
if(argc != 1)
{
@ -240,7 +240,7 @@ int main(int argc, char * argv[])
printf("Connection to the unix socket\n");
// 1. unix socket connection
int ret = usock_connect (&usockfd, USOCK);
int32_t ret = usock_connect (&usockfd, USOCK);
if (ret != 0) {
fprintf (stderr, "error: usock_connect\n");
exit(EXIT_FAILURE);

View File

@ -63,9 +63,9 @@ void log_debug (const char* message, ...) {
va_end(args);
}
int build_socket (char *servername, char * serverport)
int32_t build_socket (char *servername, char * serverport)
{
int sockfd;
int32_t sockfd;
struct sockaddr_in6 server;
socklen_t addrlen;
@ -99,7 +99,7 @@ int build_socket (char *servername, char * serverport)
return sockfd;
}
int usock_connect (int *fd, const char *path)
int32_t usock_connect (int32_t *fd, const char *path)
{
assert (fd != NULL);
assert (path != NULL);
@ -114,7 +114,7 @@ int usock_connect (int *fd, const char *path)
return -1;
}
int sfd;
int32_t sfd;
struct sockaddr_un my_addr;
socklen_t peer_addr_size;
@ -142,7 +142,7 @@ int usock_connect (int *fd, const char *path)
return 0;
}
int usock_init (int *fd, const char *path)
int32_t usock_init (int32_t *fd, const char *path)
{
assert (fd != NULL);
assert (path != NULL);
@ -157,7 +157,7 @@ int usock_init (int *fd, const char *path)
return -1;
}
int sfd;
int32_t sfd;
struct sockaddr_un my_addr;
socklen_t peer_addr_size;
@ -195,7 +195,7 @@ int usock_init (int *fd, const char *path)
return 0;
}
int usock_accept (int fd, int *pfd)
int32_t usock_accept (int32_t fd, int32_t *pfd)
{
assert (pfd != NULL);
@ -218,9 +218,9 @@ int usock_accept (int fd, int *pfd)
return 0;
}
int usock_close (int fd)
int32_t usock_close (int32_t fd)
{
int ret;
int32_t ret;
ret = close (fd);
if (ret < 0) {
handle_err ("usock_close", "close ret < 0");
@ -229,14 +229,14 @@ int usock_close (int fd)
return ret;
}
int usock_remove (const char *path)
int32_t usock_remove (const char *path)
{
return unlink (path);
}
int build_unix_socket (char * path)
int32_t build_unix_socket (char * path)
{
int remotefd, localfd;
int32_t remotefd, localfd;
usock_init (&localfd, path);
usock_accept (localfd, &remotefd);
@ -245,7 +245,7 @@ int build_unix_socket (char * path)
}
static
void sendfd (int socket, int fd) // send fd by socket
void sendfd (int32_t socket, int32_t fd) // send fd by socket
{
struct ipc_messagehdr msg = { 0 };
char buf[CMSG_SPACE(sizeof(fd))];
@ -272,7 +272,7 @@ void sendfd (int socket, int fd) // send fd by socket
handle_err("sendfd", "Failed to send message\n");
}
int main(int argc, char * argv[])
int32_t main(int32_t argc, char * argv[])
{
// check the number of args on command line
if(argc != 3)
@ -285,7 +285,7 @@ int main(int argc, char * argv[])
printf("Connection to the tcp socket\n");
// 1. socket creation (tcp), connection to the server
int sockfd = build_socket (servername, serverport);
int32_t sockfd = build_socket (servername, serverport);
printf("Sending 'coucou' to the tcp socket\n");
// send a message to check the connection is effective
@ -297,7 +297,7 @@ int main(int argc, char * argv[])
printf ("Connection to the unix socket\n");
// 2. socket creation (unix)
int usockfd = build_unix_socket (USOCK);
int32_t usockfd = build_unix_socket (USOCK);
printf ("Passing the tcp socket to the unix socket\n");
// 3. tcp socket passing to the client

View File

@ -12,7 +12,7 @@ void usage (char **argv) {
printf ("usage: echo something | msg | %s\n", argv[0]);
}
int main(int argc, char * argv[])
int32_t main(int32_t argc, char * argv[])
{
if (argc == 2 && strcmp ("-h", argv[1]) == 0) {
usage (argv);
@ -21,7 +21,7 @@ int main(int argc, char * argv[])
// read the message from the client
size_t mlen = 0;
unsigned char buf[BUFSIZ];
uint8_t buf[BUFSIZ];
mlen = read (0, buf, BUFSIZ);
/* Assuming `buffer` contains `info.st_size` bytes of input data */

View File

@ -11,7 +11,7 @@
#define PORT 2020
int main(int argc, char *argv[])
int32_t main(int32_t argc, char *argv[])
{
/* master file descriptor list */
fd_set master;
@ -23,19 +23,19 @@ int main(int argc, char *argv[])
struct sockaddr_in clientaddr;
/* maximum file descriptor number */
int fdmax;
int32_t fdmax;
/* listening socket descriptor */
int listener;
int32_t listener;
/* newly accept()ed socket descriptor */
int newfd;
int32_t newfd;
/* buffer for client data */
char buf[1024];
int nbytes;
int32_t nbytes;
/* for setsockopt() SO_REUSEADDR, below */
int yes = 1;
int addrlen;
int i, j;
int32_t yes = 1;
int32_t addrlen;
int32_t i, j;
/* clear the master and temp sets */
FD_ZERO(&master);
@ -50,7 +50,7 @@ int main(int argc, char *argv[])
printf("Server-socket() is OK...\n");
/*"address already in use" error message */
if(setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1)
if(setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int32_t)) == -1)
{
perror("Server-setsockopt() error lol!");
exit(1);

View File

@ -5,25 +5,25 @@ communication.h \- all functions explained
.nf
.B #include <communication.h>
.sp
.BI "int ipc_server_init (int "argc ", char **" argv ", char **" env ", struct ipc_service *" srv "
.BI "int32_t ipc_server_init (int32_t "argc ", char **" argv ", char **" env ", struct ipc_service *" srv "
.BI " , const char *" service_name );
.BI "int ipc_server_accept (struct ipc_service *" srv ", struct ipc_client *" p );
.BI "int32_t ipc_server_accept (struct ipc_service *" srv ", struct ipc_client *" p );
.sp
.BI "int ipc_server_read (const struct ipc_client *" p ", struct ipc_message *" message );
.BI "int ipc_server_write (const struct ipc_client *" p ", const struct ipc_message *" message );
.BI "int32_t ipc_server_read (const struct ipc_client *" p ", struct ipc_message *" message );
.BI "int32_t ipc_server_write (const struct ipc_client *" p ", const struct ipc_message *" message );
.sp
.BI "int ipc_server_close (struct ipc_service *" srv );
.BI "int ipc_server_close_client (struct ipc_client *" p );
.BI "int ipc_server_select (struct ipc_clients *" fds ", struct ipc_service *" srv ", struct ipc_clients *" readfds );
.BI "int32_t ipc_server_close (struct ipc_service *" srv );
.BI "int32_t ipc_server_close_client (struct ipc_client *" p );
.BI "int32_t ipc_server_select (struct ipc_clients *" fds ", struct ipc_service *" srv ", struct ipc_clients *" readfds );
.BI "int ipc_application_connection (int " argc ", char **" argv ", char **" env ", struct ipc_service *" srv
.BI "int32_t ipc_application_connection (int32_t " argc ", char **" argv ", char **" env ", struct ipc_service *" srv
.BI " , const char *" service_name "
.BI " , const char *" connection_buffer ", size_t " bufsize );
.sp
.BI "int ipc_application_read (const struct ipc_service *" srv ", struct ipc_message *" message );
.BI "int ipc_application_write (const struct ipc_service *" srv ", const struct ipc_message *" message );
.BI "int32_t ipc_application_read (const struct ipc_service *" srv ", struct ipc_message *" message );
.BI "int32_t ipc_application_write (const struct ipc_service *" srv ", const struct ipc_message *" message );
.sp
.BI "int ipc_application_close (struct ipc_service *" srv );
.BI "int32_t ipc_application_close (struct ipc_service *" srv );
.fi

View File

@ -5,6 +5,8 @@
#include <readline/readline.h>
#include <readline/history.h>
#include <stdint.h>
#include "../../core/communication.h"
#include "../../core/error.h"