cleaning names
parent
21434c600e
commit
e48b5f2ce4
|
@ -5,8 +5,8 @@
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct ipc_client_array tab_proc;
|
struct ipc_client_array clients;
|
||||||
memset(&tab_proc, 0, sizeof(struct ipc_client_array));
|
memset(&clients, 0, sizeof(struct ipc_client_array));
|
||||||
|
|
||||||
struct ipc_client client_tab[5];
|
struct ipc_client client_tab[5];
|
||||||
memset(&client_tab, 0, sizeof(struct ipc_client) * 5);
|
memset(&client_tab, 0, sizeof(struct ipc_client) * 5);
|
||||||
|
@ -14,21 +14,21 @@ int main()
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
client_tab[i].proc_fd = i;
|
client_tab[i].proc_fd = i;
|
||||||
ret = ipc_client_add(&tab_proc, &client_tab[i]);
|
ret = ipc_client_add(&clients, &client_tab[i]);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
printf("erreur realloc\n");
|
printf("erreur realloc\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ipc_client_array_print(&tab_proc);
|
ipc_client_array_print(&clients);
|
||||||
|
|
||||||
ret = ipc_client_del(&tab_proc, &client_tab[2]);
|
ret = ipc_client_del(&clients, &client_tab[2]);
|
||||||
if(ret < 0) {
|
if(ret < 0) {
|
||||||
printf("erreur %d\n", ret );
|
printf("erreur %d\n", ret );
|
||||||
}
|
}
|
||||||
ipc_client_array_print(&tab_proc);
|
ipc_client_array_print(&clients);
|
||||||
|
|
||||||
ipc_client_array_free (&tab_proc);
|
ipc_client_array_free (&clients);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ int main (int argc, char *argv[], char *env[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("msg recv: %s\n", m.val);
|
printf ("msg recv: %s\n", m.payload);
|
||||||
ipc_message_free (&m);
|
ipc_message_free (&m);
|
||||||
|
|
||||||
if (application_close (&srv) < 0) {
|
if (application_close (&srv) < 0) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ int main (int argc, char *argv[], char *env[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("msg recv: %s\n", m.val);
|
printf ("msg recv: %s\n", m.payload);
|
||||||
|
|
||||||
if (server_write (&p, &m) < 0) {
|
if (server_write (&p, &m) < 0) {
|
||||||
handle_err("main", "server_write < 0");
|
handle_err("main", "server_write < 0");
|
||||||
|
@ -60,8 +60,8 @@ int main (int argc, char *argv[], char *env[])
|
||||||
}
|
}
|
||||||
ipc_message_free (&m);
|
ipc_message_free (&m);
|
||||||
|
|
||||||
if (server_close_proc (&p) < 0) {
|
if (server_close_client (&p) < 0) {
|
||||||
handle_err("main", "server_close_proc < 0");
|
handle_err("main", "server_close_client < 0");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,45 +29,45 @@ void ipc_server_client_gen (struct ipc_client *p
|
||||||
p->index = index;
|
p->index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipc_client_add (struct ipc_client_array *aproc, struct ipc_client *p)
|
int ipc_client_add (struct ipc_client_array *clients, struct ipc_client *p)
|
||||||
{
|
{
|
||||||
assert(aproc != NULL);
|
assert(clients != NULL);
|
||||||
assert(p != NULL);
|
assert(p != NULL);
|
||||||
aproc->size++;
|
clients->size++;
|
||||||
aproc->tab_proc = realloc(aproc->tab_proc
|
clients->clients = realloc(clients->clients
|
||||||
, sizeof(struct ipc_client) * aproc->size);
|
, sizeof(struct ipc_client) * clients->size);
|
||||||
|
|
||||||
if (aproc->tab_proc == NULL) {
|
if (clients->clients == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
aproc->tab_proc[aproc->size - 1] = p;
|
clients->clients[clients->size - 1] = p;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipc_client_del (struct ipc_client_array *aproc, struct ipc_client *p)
|
int ipc_client_del (struct ipc_client_array *clients, struct ipc_client *p)
|
||||||
{
|
{
|
||||||
assert(aproc != NULL);
|
assert(clients != NULL);
|
||||||
assert(p != NULL);
|
assert(p != NULL);
|
||||||
|
|
||||||
if (aproc->tab_proc == NULL) {
|
if (clients->clients == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < aproc->size; i++) {
|
for (i = 0; i < clients->size; i++) {
|
||||||
if (aproc->tab_proc[i] == p) {
|
if (clients->clients[i] == p) {
|
||||||
|
|
||||||
aproc->tab_proc[i] = aproc->tab_proc[aproc->size-1];
|
clients->clients[i] = clients->clients[clients->size-1];
|
||||||
aproc->size--;
|
clients->size--;
|
||||||
if (aproc->size == 0) {
|
if (clients->size == 0) {
|
||||||
ipc_client_array_free (aproc);
|
ipc_client_array_free (clients);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
aproc->tab_proc = realloc(aproc->tab_proc
|
clients->clients = realloc(clients->clients
|
||||||
, sizeof(struct ipc_client) * aproc->size);
|
, sizeof(struct ipc_client) * clients->size);
|
||||||
|
|
||||||
if (aproc->tab_proc == NULL) {
|
if (clients->clients == NULL) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,15 +91,15 @@ void ipc_client_array_print (struct ipc_client_array *ap)
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < ap->size; i++) {
|
for (i = 0; i < ap->size; i++) {
|
||||||
printf("%d : ", i);
|
printf("%d : ", i);
|
||||||
client_print(ap->tab_proc[i]);
|
client_print(ap->clients[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipc_client_array_free (struct ipc_client_array *ap)
|
void ipc_client_array_free (struct ipc_client_array *ap)
|
||||||
{
|
{
|
||||||
if (ap->tab_proc != NULL) {
|
if (ap->clients != NULL) {
|
||||||
free (ap->tab_proc);
|
free (ap->clients);
|
||||||
ap->tab_proc = NULL;
|
ap->clients = NULL;
|
||||||
}
|
}
|
||||||
ap->size = 0;
|
ap->size = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,12 @@ struct ipc_client {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ipc_client_array {
|
struct ipc_client_array {
|
||||||
struct ipc_client **tab_proc;
|
struct ipc_client **clients;
|
||||||
int size;
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
int ipc_client_add (struct ipc_client_array *, struct ipc_client *);
|
int ipc_client_add (struct ipc_client_array *, struct ipc_client *);
|
||||||
int ipc_client_del (struct ipc_client_array *aproc, struct ipc_client *p);
|
int ipc_client_del (struct ipc_client_array *clients, struct ipc_client *p);
|
||||||
|
|
||||||
void ipc_client_array_print (struct ipc_client_array *);
|
void ipc_client_array_print (struct ipc_client_array *);
|
||||||
void ipc_client_array_free (struct ipc_client_array *);
|
void ipc_client_array_free (struct ipc_client_array *);
|
||||||
|
|
|
@ -65,14 +65,14 @@ int ipc_server_close (struct ipc_service *srv)
|
||||||
return usock_remove (srv->spath);
|
return usock_remove (srv->spath);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipc_server_close_proc (struct ipc_client *p)
|
int ipc_server_close_client (struct ipc_client *p)
|
||||||
{
|
{
|
||||||
// struct ipc_message m_ack_dis;
|
// struct ipc_message m_ack_dis;
|
||||||
// memset (&m_ack_dis, 0, sizeof (struct ipc_message));
|
// memset (&m_ack_dis, 0, sizeof (struct ipc_message));
|
||||||
// m_ack_dis.type = MSG_TYPE_CLOSE;
|
// m_ack_dis.type = MSG_TYPE_CLOSE;
|
||||||
|
|
||||||
// if (ipc_message_write (p->proc_fd, &m_ack_dis) < 0) {
|
// if (ipc_message_write (p->proc_fd, &m_ack_dis) < 0) {
|
||||||
// handle_err ("server_close_proc", "ipc_message_write < 0");
|
// handle_err ("server_close_client", "ipc_message_write < 0");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return usock_close (p->proc_fd);
|
return usock_close (p->proc_fd);
|
||||||
|
@ -128,7 +128,7 @@ int ipc_application_connection (int argc, char **argv, char **env
|
||||||
ipc_application_read (srv, &m_ack);
|
ipc_application_read (srv, &m_ack);
|
||||||
|
|
||||||
assert (m_ack.type == MSG_TYPE_ACK);
|
assert (m_ack.type == MSG_TYPE_ACK);
|
||||||
assert (m_ack.valsize == 0);
|
assert (m_ack.length == 0);
|
||||||
ipc_message_free (&m_ack);
|
ipc_message_free (&m_ack);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -166,8 +166,8 @@ static int getMaxFd(struct ipc_client_array *ap)
|
||||||
int max = 0;
|
int max = 0;
|
||||||
|
|
||||||
for (i = 0; i < ap->size; i++ ) {
|
for (i = 0; i < ap->size; i++ ) {
|
||||||
if (ap->tab_proc[i]->proc_fd > max) {
|
if (ap->clients[i]->proc_fd > max) {
|
||||||
max = ap->tab_proc[i]->proc_fd;
|
max = ap->clients[i]->proc_fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,13 +188,13 @@ static int getMaxFd(struct ipc_client_array *ap)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ipc_server_select (struct ipc_client_array *ap, struct ipc_service *srv
|
int ipc_server_select (struct ipc_client_array *ap, struct ipc_service *srv
|
||||||
, struct ipc_client_array *proc)
|
, struct ipc_client_array *client)
|
||||||
{
|
{
|
||||||
assert (ap != NULL);
|
assert (ap != NULL);
|
||||||
assert (proc != NULL);
|
assert (client != NULL);
|
||||||
|
|
||||||
// delete previous read client array
|
// delete previous read client array
|
||||||
ipc_client_array_free (proc);
|
ipc_client_array_free (client);
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
/* master file descriptor list */
|
/* master file descriptor list */
|
||||||
|
@ -213,7 +213,7 @@ int ipc_server_select (struct ipc_client_array *ap, struct ipc_service *srv
|
||||||
FD_SET(listener, &master);
|
FD_SET(listener, &master);
|
||||||
|
|
||||||
for (i=0; i < ap->size; i++) {
|
for (i=0; i < ap->size; i++) {
|
||||||
FD_SET(ap->tab_proc[i]->proc_fd, &master);
|
FD_SET(ap->clients[i]->proc_fd, &master);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keep track of the biggest file descriptor */
|
/* keep track of the biggest file descriptor */
|
||||||
|
@ -238,8 +238,8 @@ int ipc_server_select (struct ipc_client_array *ap, struct ipc_service *srv
|
||||||
} else {
|
} else {
|
||||||
for(j = 0; j < ap->size; j++) {
|
for(j = 0; j < ap->size; j++) {
|
||||||
// printf ("loop ipc_server_select inner inner loop\n");
|
// printf ("loop ipc_server_select inner inner loop\n");
|
||||||
if(i == ap->tab_proc[j]->proc_fd ) {
|
if(i == ap->clients[j]->proc_fd ) {
|
||||||
ipc_client_add (proc, ap->tab_proc[j]);
|
ipc_client_add (client, ap->clients[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,9 +247,9 @@ int ipc_server_select (struct ipc_client_array *ap, struct ipc_service *srv
|
||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
if (proc->size > 0 && is_listener)
|
if (client->size > 0 && is_listener)
|
||||||
return CON_APP;
|
return CON_APP;
|
||||||
if (proc->size > 0)
|
if (client->size > 0)
|
||||||
return APPLICATION;
|
return APPLICATION;
|
||||||
return CONNECTION;
|
return CONNECTION;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct ipc_service {
|
||||||
int ipc_server_init (int argc, char **argv, char **env
|
int ipc_server_init (int argc, char **argv, char **env
|
||||||
, struct ipc_service *srv, const char *sname);
|
, struct ipc_service *srv, const char *sname);
|
||||||
int ipc_server_close (struct ipc_service *srv);
|
int ipc_server_close (struct ipc_service *srv);
|
||||||
int ipc_server_close_proc (struct ipc_client *p);
|
int ipc_server_close_client (struct ipc_client *p);
|
||||||
int ipc_server_accept (struct ipc_service *srv, struct ipc_client *p);
|
int ipc_server_accept (struct ipc_service *srv, struct ipc_client *p);
|
||||||
|
|
||||||
int ipc_server_read (const struct ipc_client *, struct ipc_message *m);
|
int ipc_server_read (const struct ipc_client *, struct ipc_message *m);
|
||||||
|
|
64
core/msg.c
64
core/msg.c
|
@ -7,7 +7,7 @@
|
||||||
void ipc_message_print (const struct ipc_message *m)
|
void ipc_message_print (const struct ipc_message *m)
|
||||||
{
|
{
|
||||||
assert (m != NULL);
|
assert (m != NULL);
|
||||||
printf ("msg: type %d len %d\n", m->type, m->valsize);
|
printf ("msg: type %d len %d\n", m->type, m->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipc_message_format_read (struct ipc_message *m, const char *buf, size_t msize)
|
int ipc_message_format_read (struct ipc_message *m, const char *buf, size_t msize)
|
||||||
|
@ -20,18 +20,18 @@ int ipc_message_format_read (struct ipc_message *m, const char *buf, size_t msiz
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
m->type = buf[0];
|
m->type = buf[0];
|
||||||
memcpy (&m->valsize, buf+1, 2);
|
memcpy (&m->length, buf+1, 2);
|
||||||
|
|
||||||
assert (m->valsize <= BUFSIZ -3);
|
assert (m->length <= BUFSIZ -3);
|
||||||
// printf ("type %d : msize = %ld, valsize = %d\n", m->type, msize, m->valsize);
|
// printf ("type %d : msize = %ld, length = %d\n", m->type, msize, m->length);
|
||||||
assert (m->valsize == msize - 3);
|
assert (m->length == msize - 3);
|
||||||
|
|
||||||
if (m->val != NULL)
|
if (m->payload != NULL)
|
||||||
free (m->val), m->val = NULL;
|
free (m->payload), m->payload = NULL;
|
||||||
|
|
||||||
if (m->val == NULL && m->valsize > 0) {
|
if (m->payload == NULL && m->length > 0) {
|
||||||
m->val = malloc (m->valsize);
|
m->payload = malloc (m->length);
|
||||||
memcpy (m->val, buf+3, m->valsize);
|
memcpy (m->payload, buf+3, m->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -42,7 +42,7 @@ int ipc_message_format_write (const struct ipc_message *m, char **buf, size_t *m
|
||||||
assert (m != NULL);
|
assert (m != NULL);
|
||||||
assert (buf != NULL);
|
assert (buf != NULL);
|
||||||
assert (msize != NULL);
|
assert (msize != NULL);
|
||||||
assert (m->valsize <= BUFSIZ -3);
|
assert (m->length <= BUFSIZ -3);
|
||||||
|
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -54,16 +54,16 @@ int ipc_message_format_write (const struct ipc_message *m, char **buf, size_t *m
|
||||||
return -3;
|
return -3;
|
||||||
|
|
||||||
if (*buf == NULL) {
|
if (*buf == NULL) {
|
||||||
*buf = malloc (3 + m->valsize);
|
*buf = malloc (3 + m->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *buffer = *buf;
|
char *buffer = *buf;
|
||||||
|
|
||||||
buffer[0] = m->type;
|
buffer[0] = m->type;
|
||||||
memcpy (buffer + 1, &m->valsize, 2);
|
memcpy (buffer + 1, &m->length, 2);
|
||||||
memcpy (buffer + 3, m->val, m->valsize);
|
memcpy (buffer + 3, m->payload, m->length);
|
||||||
|
|
||||||
*msize = 3 + m->valsize;
|
*msize = 3 + m->length;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -111,40 +111,40 @@ int ipc_message_write (int fd, const struct ipc_message *m)
|
||||||
|
|
||||||
// MSG FORMAT
|
// MSG FORMAT
|
||||||
|
|
||||||
int ipc_message_format (struct ipc_message *m, char type, const char *val, size_t valsize)
|
int ipc_message_format (struct ipc_message *m, char type, const char *payload, size_t length)
|
||||||
{
|
{
|
||||||
assert (m != NULL);
|
assert (m != NULL);
|
||||||
assert (valsize + 3 <= BUFSIZ);
|
assert (length + 3 <= BUFSIZ);
|
||||||
assert ((valsize == 0 && val == NULL) || (valsize > 0 && val != NULL));
|
assert ((length == 0 && payload == NULL) || (length > 0 && payload != NULL));
|
||||||
|
|
||||||
if (valsize + 3 > BUFSIZ) {
|
if (length + 3 > BUFSIZ) {
|
||||||
handle_err ("msg_format_con", "msgsize > BUFSIZ");
|
handle_err ("msg_format_con", "msgsize > BUFSIZ");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
m->type = type;
|
m->type = type;
|
||||||
m->valsize = (short) valsize;
|
m->length = (short) length;
|
||||||
|
|
||||||
if (m->val == NULL)
|
if (m->payload == NULL)
|
||||||
m->val = malloc (valsize);
|
m->payload = malloc (length);
|
||||||
|
|
||||||
memcpy (m->val, val, valsize);
|
memcpy (m->payload, payload, length);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipc_message_format_con (struct ipc_message *m, const char *val, size_t valsize)
|
int ipc_message_format_con (struct ipc_message *m, const char *payload, size_t length)
|
||||||
{
|
{
|
||||||
return ipc_message_format (m, MSG_TYPE_CON, val, valsize);
|
return ipc_message_format (m, MSG_TYPE_CON, payload, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipc_message_format_data (struct ipc_message *m, const char *val, size_t valsize)
|
int ipc_message_format_data (struct ipc_message *m, const char *payload, size_t length)
|
||||||
{
|
{
|
||||||
return ipc_message_format (m, MSG_TYPE_DATA, val, valsize);
|
return ipc_message_format (m, MSG_TYPE_DATA, payload, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipc_message_format_ack (struct ipc_message *m, const char *val, size_t valsize)
|
int ipc_message_format_ack (struct ipc_message *m, const char *payload, size_t length)
|
||||||
{
|
{
|
||||||
return ipc_message_format (m, MSG_TYPE_ACK, val, valsize);
|
return ipc_message_format (m, MSG_TYPE_ACK, payload, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipc_message_free (struct ipc_message *m)
|
int ipc_message_free (struct ipc_message *m)
|
||||||
|
@ -154,10 +154,10 @@ int ipc_message_free (struct ipc_message *m)
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (m->val != NULL)
|
if (m->payload != NULL)
|
||||||
free (m->val), m->val = NULL;
|
free (m->payload), m->payload = NULL;
|
||||||
|
|
||||||
m->valsize = 0;
|
m->length = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
10
core/msg.h
10
core/msg.h
|
@ -13,8 +13,8 @@
|
||||||
|
|
||||||
struct ipc_message {
|
struct ipc_message {
|
||||||
char type;
|
char type;
|
||||||
unsigned short valsize;
|
unsigned short length;
|
||||||
char *val;
|
char *payload;
|
||||||
};
|
};
|
||||||
|
|
||||||
// used to create msg structure from buffer
|
// used to create msg structure from buffer
|
||||||
|
@ -27,9 +27,9 @@ int ipc_message_read (int fd, struct ipc_message *m);
|
||||||
// write a structure msg to fd
|
// write a structure msg to fd
|
||||||
int ipc_message_write (int fd, const struct ipc_message *m);
|
int ipc_message_write (int fd, const struct ipc_message *m);
|
||||||
|
|
||||||
int ipc_message_format_con (struct ipc_message *m, const char *val, size_t valsize);
|
int ipc_message_format_con (struct ipc_message *m, const char *payload, size_t length);
|
||||||
int ipc_message_format_data (struct ipc_message *m, const char *val, size_t valsize);
|
int ipc_message_format_data (struct ipc_message *m, const char *payload, size_t length);
|
||||||
int ipc_message_format_ack (struct ipc_message *m, const char *val, size_t valsize);
|
int ipc_message_format_ack (struct ipc_message *m, const char *payload, size_t length);
|
||||||
|
|
||||||
int ipc_message_free (struct ipc_message *m);
|
int ipc_message_free (struct ipc_message *m);
|
||||||
void ipc_message_print (const struct ipc_message *m);
|
void ipc_message_print (const struct ipc_message *m);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
void print_hexa (const char *prefix, unsigned char *val, size_t size)
|
void print_hexa (const char *prefix, unsigned char *payload, size_t size)
|
||||||
{
|
{
|
||||||
if (! val)
|
if (! payload)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -10,7 +10,7 @@ void print_hexa (const char *prefix, unsigned char *val, size_t size)
|
||||||
{
|
{
|
||||||
if(! (i % 4))
|
if(! (i % 4))
|
||||||
printf("\n%s (%ld) ", prefix, size);
|
printf("\n%s (%ld) ", prefix, size);
|
||||||
printf("%2x ", val[i]);
|
printf("%2x ", payload[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void print_hexa (const char *prefix, unsigned char *val, size_t size);
|
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, unsigned char *buf, size_t length);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,7 +13,7 @@ communication.h \- all functions explained
|
||||||
.BI "int ipc_server_write (const struct ipc_client *" p ", const struct ipc_message *" message );
|
.BI "int ipc_server_write (const struct ipc_client *" p ", const struct ipc_message *" message );
|
||||||
.sp
|
.sp
|
||||||
.BI "int ipc_server_close (struct ipc_service *" srv );
|
.BI "int ipc_server_close (struct ipc_service *" srv );
|
||||||
.BI "int ipc_server_close_proc (struct ipc_client *" p );
|
.BI "int ipc_server_close_client (struct ipc_client *" p );
|
||||||
.BI "int ipc_server_select (struct ipc_client_array *" fds ", struct ipc_service *" srv ", struct ipc_client_array *" readfds );
|
.BI "int ipc_server_select (struct ipc_client_array *" fds ", struct ipc_service *" srv ", struct ipc_client_array *" readfds );
|
||||||
|
|
||||||
.BI "int ipc_application_connection (int " argc ", char **" argv ", char **" env ", struct ipc_service *" srv
|
.BI "int ipc_application_connection (int " argc ", char **" argv ", char **" env ", struct ipc_service *" srv
|
||||||
|
@ -55,7 +55,7 @@ and
|
||||||
functions take respectively a message to read from, and a message to write to a client.
|
functions take respectively a message to read from, and a message to write to a client.
|
||||||
.PP
|
.PP
|
||||||
The
|
The
|
||||||
.BR ipc_server_close_proc ()
|
.BR ipc_server_close_client ()
|
||||||
and
|
and
|
||||||
.BR ipc_server_close ()
|
.BR ipc_server_close ()
|
||||||
functions terminate respectively a client (closing its unix socket) and the service (closing and removing its named unix socket).
|
functions terminate respectively a client (closing its unix socket) and the service (closing and removing its named unix socket).
|
||||||
|
|
|
@ -42,7 +42,7 @@ void non_interactive (int argc, char *argv[], char *env[])
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("msg recv: %s\n", m.val);
|
printf ("msg recv: %s\n", m.payload);
|
||||||
ipc_message_free (&m);
|
ipc_message_free (&m);
|
||||||
|
|
||||||
if (ipc_application_close (&srv) < 0) {
|
if (ipc_application_close (&srv) < 0) {
|
||||||
|
@ -96,7 +96,7 @@ void interactive (int argc, char *argv[], char *env[])
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("msg recv: %s", m.val);
|
printf ("msg recv: %s", m.payload);
|
||||||
ipc_message_free (&m);
|
ipc_message_free (&m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ void handle_new_msg (struct ipc_client_array *ap, struct ipc_client_array *proc_
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < proc_to_read->size; i++) {
|
for (i = 0; i < proc_to_read->size; i++) {
|
||||||
// printf ("loop handle_new_msg\n");
|
// printf ("loop handle_new_msg\n");
|
||||||
if (ipc_server_read (proc_to_read->tab_proc[i], &m) < 0) {
|
if (ipc_server_read (proc_to_read->clients[i], &m) < 0) {
|
||||||
handle_error("server_read < 0");
|
handle_error("server_read < 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,18 +45,18 @@ void handle_new_msg (struct ipc_client_array *ap, struct ipc_client_array *proc_
|
||||||
cpt--;
|
cpt--;
|
||||||
printf ("disconnection => %d client(s) remaining\n", cpt);
|
printf ("disconnection => %d client(s) remaining\n", cpt);
|
||||||
|
|
||||||
if (ipc_server_close_proc (proc_to_read->tab_proc[i]) < 0)
|
if (ipc_server_close_client (proc_to_read->clients[i]) < 0)
|
||||||
handle_err( "handle_new_msg", "server_close_proc < 0");
|
handle_err( "handle_new_msg", "server_close_client < 0");
|
||||||
if (ipc_client_del (ap, proc_to_read->tab_proc[i]) < 0)
|
if (ipc_client_del (ap, proc_to_read->clients[i]) < 0)
|
||||||
handle_err( "handle_new_msg", "ipc_client_del < 0");
|
handle_err( "handle_new_msg", "ipc_client_del < 0");
|
||||||
if (ipc_client_del (proc_to_read, proc_to_read->tab_proc[i]) < 0)
|
if (ipc_client_del (proc_to_read, proc_to_read->clients[i]) < 0)
|
||||||
handle_err( "handle_new_msg", "ipc_client_del < 0");
|
handle_err( "handle_new_msg", "ipc_client_del < 0");
|
||||||
i--;
|
i--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("new message : %s", m.val);
|
printf ("new message : %s", m.payload);
|
||||||
if (ipc_server_write (proc_to_read->tab_proc[i], &m) < 0) {
|
if (ipc_server_write (proc_to_read->clients[i], &m) < 0) {
|
||||||
handle_err( "handle_new_msg", "server_write < 0");
|
handle_err( "handle_new_msg", "server_write < 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,8 +98,8 @@ void main_loop (struct ipc_service *srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ap.size; i++) {
|
for (i = 0; i < ap.size; i++) {
|
||||||
if (ipc_server_close_proc (ap.tab_proc[i]) < 0) {
|
if (ipc_server_close_client (ap.clients[i]) < 0) {
|
||||||
handle_error( "server_close_proc < 0");
|
handle_error( "server_close_client < 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ int pubsub_message_recv (struct ipc_service *srv, struct pubsub_msg *m)
|
||||||
memset (&m_recv, 0, sizeof (struct ipc_message));
|
memset (&m_recv, 0, sizeof (struct ipc_message));
|
||||||
|
|
||||||
ipc_application_read (srv, &m_recv);
|
ipc_application_read (srv, &m_recv);
|
||||||
pubsub_message_unserialize (m, m_recv.val, m_recv.valsize);
|
pubsub_message_unserialize (m, m_recv.payload, m_recv.length);
|
||||||
|
|
||||||
ipc_message_free (&m_recv);
|
ipc_message_free (&m_recv);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ void pubsubd_send (const struct ipc_client_array *ap, const struct pubsub_msg *
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < ap->size ; i++) {
|
for (i = 0; i < ap->size ; i++) {
|
||||||
ipc_server_write (ap->tab_proc[i], &m_data);
|
ipc_server_write (ap->clients[i], &m_data);
|
||||||
}
|
}
|
||||||
ipc_message_free (&m_data);
|
ipc_message_free (&m_data);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ void pubsubd_send (const struct ipc_client_array *ap, const struct pubsub_msg *
|
||||||
// // read the message from the client
|
// // read the message from the client
|
||||||
// ipc_server_read (p, &m_data);
|
// ipc_server_read (p, &m_data);
|
||||||
//
|
//
|
||||||
// pubsub_message_unserialize (m, m_data.val, m_data.valsize);
|
// pubsub_message_unserialize (m, m_data.payload, m_data.length);
|
||||||
//
|
//
|
||||||
// ipc_message_free (&m_data);
|
// ipc_message_free (&m_data);
|
||||||
// }
|
// }
|
||||||
|
@ -83,24 +83,24 @@ void handle_new_msg (struct channels *chans
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < proc_to_read->size; i++) {
|
for (i = 0; i < proc_to_read->size; i++) {
|
||||||
// printf ("loop handle_new_msg\n");
|
// printf ("loop handle_new_msg\n");
|
||||||
if (ipc_server_read (proc_to_read->tab_proc[i], &m) < 0) {
|
if (ipc_server_read (proc_to_read->clients[i], &m) < 0) {
|
||||||
handle_error("server_read < 0");
|
handle_error("server_read < 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
mprint_hexa ("msg received: ", (unsigned char *) m.val, m.valsize);
|
mprint_hexa ("msg received: ", (unsigned char *) m.payload, m.length);
|
||||||
|
|
||||||
// close the client then delete it from the client array
|
// close the client then delete it from the client array
|
||||||
if (m.type == MSG_TYPE_CLOSE) {
|
if (m.type == MSG_TYPE_CLOSE) {
|
||||||
struct ipc_client *p = proc_to_read->tab_proc[i];
|
struct ipc_client *p = proc_to_read->clients[i];
|
||||||
|
|
||||||
printf ("proc %d disconnecting\n", p->proc_fd);
|
printf ("client %d disconnecting\n", p->proc_fd);
|
||||||
|
|
||||||
// TODO: to test, unsubscribe when closing
|
// TODO: to test, unsubscribe when closing
|
||||||
pubsubd_channels_unsubscribe_everywhere (chans, p);
|
pubsubd_channels_unsubscribe_everywhere (chans, p);
|
||||||
|
|
||||||
// close the connection to the client
|
// close the connection to the client
|
||||||
if (ipc_server_close_proc (p) < 0)
|
if (ipc_server_close_client (p) < 0)
|
||||||
handle_error( "server_close_proc < 0");
|
handle_error( "server_close_client < 0");
|
||||||
|
|
||||||
|
|
||||||
// remove the client from the clientes list
|
// remove the client from the clientes list
|
||||||
|
@ -121,27 +121,27 @@ void handle_new_msg (struct channels *chans
|
||||||
struct pubsub_msg m_data;
|
struct pubsub_msg m_data;
|
||||||
memset (&m_data, 0, sizeof (struct pubsub_msg));
|
memset (&m_data, 0, sizeof (struct pubsub_msg));
|
||||||
|
|
||||||
pubsub_message_unserialize (&m_data, m.val, m.valsize);
|
pubsub_message_unserialize (&m_data, m.payload, m.length);
|
||||||
|
|
||||||
if (m_data.type == PUBSUB_MSG_TYPE_SUB) {
|
if (m_data.type == PUBSUB_MSG_TYPE_SUB) {
|
||||||
printf ("proc %d subscribing to %s\n"
|
printf ("client %d subscribing to %s\n"
|
||||||
, proc_to_read->tab_proc[i]->proc_fd
|
, proc_to_read->clients[i]->proc_fd
|
||||||
, m_data.chan);
|
, m_data.chan);
|
||||||
pubsubd_channels_subscribe (chans
|
pubsubd_channels_subscribe (chans
|
||||||
, m_data.chan, proc_to_read->tab_proc[i]);
|
, m_data.chan, proc_to_read->clients[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_data.type == PUBSUB_MSG_TYPE_UNSUB) {
|
if (m_data.type == PUBSUB_MSG_TYPE_UNSUB) {
|
||||||
printf ("proc %d unsubscribing to %s\n"
|
printf ("client %d unsubscribing to %s\n"
|
||||||
, proc_to_read->tab_proc[i]->proc_fd
|
, proc_to_read->clients[i]->proc_fd
|
||||||
, m_data.chan);
|
, m_data.chan);
|
||||||
pubsubd_channels_unsubscribe (chans
|
pubsubd_channels_unsubscribe (chans
|
||||||
, m_data.chan, proc_to_read->tab_proc[i]);
|
, m_data.chan, proc_to_read->clients[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_data.type == PUBSUB_MSG_TYPE_PUB) {
|
if (m_data.type == PUBSUB_MSG_TYPE_PUB) {
|
||||||
printf ("proc %d publishing to %s\n"
|
printf ("client %d publishing to %s\n"
|
||||||
, proc_to_read->tab_proc[i]->proc_fd
|
, proc_to_read->clients[i]->proc_fd
|
||||||
, m_data.chan);
|
, m_data.chan);
|
||||||
struct channel *chan = pubsubd_channel_search (chans, m_data.chan);
|
struct channel *chan = pubsubd_channel_search (chans, m_data.chan);
|
||||||
if (chan == NULL) {
|
if (chan == NULL) {
|
||||||
|
@ -190,8 +190,8 @@ void pubsubd_main_loop (struct ipc_service *srv, struct channels *chans)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ap.size; i++) {
|
for (i = 0; i < ap.size; i++) {
|
||||||
if (ipc_server_close_proc (ap.tab_proc[i]) < 0) {
|
if (ipc_server_close_client (ap.clients[i]) < 0) {
|
||||||
handle_error( "server_close_proc < 0");
|
handle_error( "server_close_client < 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ int remotec_message_recv (struct ipc_service *srv, struct remoted_msg *m)
|
||||||
memset (&m_recv, 0, sizeof (struct ipc_message));
|
memset (&m_recv, 0, sizeof (struct ipc_message));
|
||||||
|
|
||||||
ipc_application_read (srv, &m_recv);
|
ipc_application_read (srv, &m_recv);
|
||||||
remote_message_unserialize (m, m_recv.val, m_recv.valsize);
|
remote_message_unserialize (m, m_recv.payload, m_recv.length);
|
||||||
|
|
||||||
ipc_message_free (&m_recv);
|
ipc_message_free (&m_recv);
|
||||||
|
|
||||||
|
|
|
@ -37,21 +37,21 @@ void handle_new_msg (struct ipc_client_array *ap, struct ipc_client_array *proc_
|
||||||
memset (&m, 0, sizeof (struct ipc_message));
|
memset (&m, 0, sizeof (struct ipc_message));
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < proc_to_read->size; i++) {
|
for (i = 0; i < proc_to_read->size; i++) {
|
||||||
if (ipc_server_read (proc_to_read->tab_proc[i], &m) < 0) {
|
if (ipc_server_read (proc_to_read->clients[i], &m) < 0) {
|
||||||
handle_error("ipc_server_read < 0");
|
handle_error("ipc_server_read < 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
mprint_hexa ("msg received: ", (unsigned char *) m.val, m.valsize);
|
mprint_hexa ("msg received: ", (unsigned char *) m.payload, m.length);
|
||||||
|
|
||||||
// close the client then delete it from the client array
|
// close the client then delete it from the client array
|
||||||
if (m.type == MSG_TYPE_CLOSE) {
|
if (m.type == MSG_TYPE_CLOSE) {
|
||||||
struct ipc_client *p = proc_to_read->tab_proc[i];
|
struct ipc_client *p = proc_to_read->clients[i];
|
||||||
|
|
||||||
log_debug ("remoted, proc %d disconnecting", p->proc_fd);
|
log_debug ("remoted, client %d disconnecting", p->proc_fd);
|
||||||
|
|
||||||
// close the connection to the client
|
// close the connection to the client
|
||||||
if (ipc_server_close_proc (p) < 0)
|
if (ipc_server_close_client (p) < 0)
|
||||||
handle_error( "ipc_server_close_proc < 0");
|
handle_error( "ipc_server_close_client < 0");
|
||||||
|
|
||||||
// remove the client from the clientes list
|
// remove the client from the clientes list
|
||||||
if (ipc_client_del (ap, p) < 0)
|
if (ipc_client_del (ap, p) < 0)
|
||||||
|
@ -72,27 +72,27 @@ void handle_new_msg (struct ipc_client_array *ap, struct ipc_client_array *proc_
|
||||||
struct pubsub_msg m_data;
|
struct pubsub_msg m_data;
|
||||||
memset (&m_data, 0, sizeof (struct pubsub_msg));
|
memset (&m_data, 0, sizeof (struct pubsub_msg));
|
||||||
|
|
||||||
pubsub_message_unserialize (&m_data, m.val, m.valsize);
|
pubsub_message_unserialize (&m_data, m.payload, m.length);
|
||||||
|
|
||||||
if (m_data.type == PUBSUB_MSG_TYPE_SUB) {
|
if (m_data.type == PUBSUB_MSG_TYPE_SUB) {
|
||||||
printf ("proc %d subscribing to %s\n"
|
printf ("client %d subscribing to %s\n"
|
||||||
, proc_to_read->tab_proc[i]->proc_fd
|
, proc_to_read->clients[i]->proc_fd
|
||||||
, m_data.chan);
|
, m_data.chan);
|
||||||
pubsubd_channels_subscribe (chans
|
pubsubd_channels_subscribe (chans
|
||||||
, m_data.chan, proc_to_read->tab_proc[i]);
|
, m_data.chan, proc_to_read->clients[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_data.type == PUBSUB_MSG_TYPE_UNSUB) {
|
if (m_data.type == PUBSUB_MSG_TYPE_UNSUB) {
|
||||||
printf ("proc %d unsubscribing to %s\n"
|
printf ("client %d unsubscribing to %s\n"
|
||||||
, proc_to_read->tab_proc[i]->proc_fd
|
, proc_to_read->clients[i]->proc_fd
|
||||||
, m_data.chan);
|
, m_data.chan);
|
||||||
pubsubd_channels_unsubscribe (chans
|
pubsubd_channels_unsubscribe (chans
|
||||||
, m_data.chan, proc_to_read->tab_proc[i]);
|
, m_data.chan, proc_to_read->clients[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_data.type == PUBSUB_MSG_TYPE_PUB) {
|
if (m_data.type == PUBSUB_MSG_TYPE_PUB) {
|
||||||
printf ("proc %d publishing to %s\n"
|
printf ("client %d publishing to %s\n"
|
||||||
, proc_to_read->tab_proc[i]->proc_fd
|
, proc_to_read->clients[i]->proc_fd
|
||||||
, m_data.chan);
|
, m_data.chan);
|
||||||
struct channel *chan = pubsubd_channel_search (chans, m_data.chan);
|
struct channel *chan = pubsubd_channel_search (chans, m_data.chan);
|
||||||
if (chan == NULL) {
|
if (chan == NULL) {
|
||||||
|
@ -136,8 +136,8 @@ void remoted_main_loop (struct ipc_service *srv, struct remoted_ctx *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ap.size; i++) {
|
for (i = 0; i < ap.size; i++) {
|
||||||
if (ipc_server_close_proc (ap.tab_proc[i]) < 0) {
|
if (ipc_server_close_client (ap.clients[i]) < 0) {
|
||||||
handle_error( "ipc_server_close_proc < 0");
|
handle_error( "ipc_server_close_client < 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue