Obsolete
/
libipc-old
Archived
3
0
Fork 0

s/process/client/g

more_to_read
Philippe PITTOLI 2018-10-04 01:22:50 +02:00
parent 4f9367b447
commit 21434c600e
25 changed files with 173 additions and 173 deletions

View File

@ -1,34 +1,34 @@
#include "../../core/process.h"
#include "../../core/client.h"
#include <string.h> /* memset */
#include <stdio.h>
int main()
{
int ret;
struct ipc_process_array tab_proc;
memset(&tab_proc, 0, sizeof(struct ipc_process_array));
struct ipc_client_array tab_proc;
memset(&tab_proc, 0, sizeof(struct ipc_client_array));
struct ipc_client process_tab[5];
memset(&process_tab, 0, sizeof(struct ipc_client) * 5);
struct ipc_client client_tab[5];
memset(&client_tab, 0, sizeof(struct ipc_client) * 5);
int i;
for (i = 0; i < 5; i++) {
process_tab[i].proc_fd = i;
ret = ipc_process_add(&tab_proc, &process_tab[i]);
client_tab[i].proc_fd = i;
ret = ipc_client_add(&tab_proc, &client_tab[i]);
if (ret == -1) {
printf("erreur realloc\n");
}
}
ipc_process_array_print(&tab_proc);
ipc_client_array_print(&tab_proc);
ret = ipc_process_del(&tab_proc, &process_tab[2]);
ret = ipc_client_del(&tab_proc, &client_tab[2]);
if(ret < 0) {
printf("erreur %d\n", ret );
}
ipc_process_array_print(&tab_proc);
ipc_client_array_print(&tab_proc);
ipc_process_array_free (&tab_proc);
ipc_client_array_free (&tab_proc);
return 0;
}

View File

@ -1,11 +1,11 @@
#include "process.h"
#include "client.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct ipc_client * ipc_server_process_copy (const struct ipc_client *p)
struct ipc_client * ipc_server_client_copy (const struct ipc_client *p)
{
if (p == NULL)
return NULL;
@ -16,20 +16,20 @@ struct ipc_client * ipc_server_process_copy (const struct ipc_client *p)
return copy;
}
int ipc_server_process_eq (const struct ipc_client *p1, const struct ipc_client *p2)
int 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_process_gen (struct ipc_client *p
void ipc_server_client_gen (struct ipc_client *p
, unsigned int index, unsigned int version)
{
p->version = version;
p->index = index;
}
int ipc_process_add (struct ipc_process_array *aproc, struct ipc_client *p)
int ipc_client_add (struct ipc_client_array *aproc, struct ipc_client *p)
{
assert(aproc != NULL);
assert(p != NULL);
@ -45,7 +45,7 @@ int ipc_process_add (struct ipc_process_array *aproc, struct ipc_client *p)
return 0;
}
int ipc_process_del (struct ipc_process_array *aproc, struct ipc_client *p)
int ipc_client_del (struct ipc_client_array *aproc, struct ipc_client *p)
{
assert(aproc != NULL);
assert(p != NULL);
@ -61,7 +61,7 @@ int ipc_process_del (struct ipc_process_array *aproc, struct ipc_client *p)
aproc->tab_proc[i] = aproc->tab_proc[aproc->size-1];
aproc->size--;
if (aproc->size == 0) {
ipc_process_array_free (aproc);
ipc_client_array_free (aproc);
}
else {
aproc->tab_proc = realloc(aproc->tab_proc
@ -79,23 +79,23 @@ int ipc_process_del (struct ipc_process_array *aproc, struct ipc_client *p)
return -3;
}
void process_print (struct ipc_client *p)
void client_print (struct ipc_client *p)
{
if (p != NULL)
printf ("process %d : index %d, version %d\n"
printf ("client %d : index %d, version %d\n"
, p->proc_fd, p->index, p->version);
}
void ipc_process_array_print (struct ipc_process_array *ap)
void ipc_client_array_print (struct ipc_client_array *ap)
{
int i;
for (i = 0; i < ap->size; i++) {
printf("%d : ", i);
process_print(ap->tab_proc[i]);
client_print(ap->tab_proc[i]);
}
}
void ipc_process_array_free (struct ipc_process_array *ap)
void ipc_client_array_free (struct ipc_client_array *ap)
{
if (ap->tab_proc != NULL) {
free (ap->tab_proc);

28
core/client.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef __IPC_PROCESS_H__
#define __IPC_PROCESS_H__
struct ipc_client {
unsigned int version;
unsigned int index;
int proc_fd;
};
struct ipc_client_array {
struct ipc_client **tab_proc;
int size;
};
int ipc_client_add (struct ipc_client_array *, struct ipc_client *);
int ipc_client_del (struct ipc_client_array *aproc, struct ipc_client *p);
void ipc_client_array_print (struct ipc_client_array *);
void ipc_client_array_free (struct ipc_client_array *);
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);
// create the service client structure
void ipc_server_client_gen (struct ipc_client *p
, unsigned int index, unsigned int version);
void client_print (struct ipc_client *);
#endif

View File

@ -159,7 +159,7 @@ int ipc_application_write (struct ipc_service *srv, const struct ipc_message *m)
/*calculer le max filedescriptor*/
int getMaxFd(struct ipc_process_array *ap)
static int getMaxFd(struct ipc_client_array *ap)
{
int i;
@ -176,25 +176,25 @@ int getMaxFd(struct ipc_process_array *ap)
/*
* ipc_server_select prend en parametre
* * un tableau de process qu'on écoute
* * un tableau de client qu'on écoute
* * le service qui attend de nouvelles connexions
* * un tableau de process qui souhaitent parler
* * un tableau de client qui souhaitent parler
*
* la fonction trouve le processus/service actif et renvoie
* la fonction trouve le clientus/service actif et renvoie
* un entier correspondant à quel descripteur de fichier il faut lire
* * celui du serveur = nouvelle connexion entrante (CONNECTION)
* * celui d'un ou plusieurs processus = ils nous parlent (APPLICATION)
* * celui d'un ou plusieurs clientus = ils nous parlent (APPLICATION)
* * les deux à la fois (CON_APP)
*/
int ipc_server_select (struct ipc_process_array *ap, struct ipc_service *srv
, struct ipc_process_array *proc)
int ipc_server_select (struct ipc_client_array *ap, struct ipc_service *srv
, struct ipc_client_array *proc)
{
assert (ap != NULL);
assert (proc != NULL);
// delete previous read process array
ipc_process_array_free (proc);
// delete previous read client array
ipc_client_array_free (proc);
int i, j;
/* master file descriptor list */
@ -239,7 +239,7 @@ int ipc_server_select (struct ipc_process_array *ap, struct ipc_service *srv
for(j = 0; j < ap->size; j++) {
// printf ("loop ipc_server_select inner inner loop\n");
if(i == ap->tab_proc[j]->proc_fd ) {
ipc_process_add (proc, ap->tab_proc[j]);
ipc_client_add (proc, ap->tab_proc[j]);
}
}
}

View File

@ -7,7 +7,7 @@
#include <errno.h> // error numbers
#include "msg.h"
#include "process.h"
#include "client.h"
#define COMMUNICATION_VERSION 1
@ -43,7 +43,7 @@ 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_write (const struct ipc_client *, const struct ipc_message *m);
int ipc_server_select (struct ipc_process_array *, struct ipc_service *, struct ipc_process_array *);
int ipc_server_select (struct ipc_client_array *, struct ipc_service *, struct ipc_client_array *);
// APPLICATION

View File

@ -1,28 +0,0 @@
#ifndef __IPC_PROCESS_H__
#define __IPC_PROCESS_H__
struct ipc_client {
unsigned int version;
unsigned int index;
int proc_fd;
};
struct ipc_process_array {
struct ipc_client **tab_proc;
int size;
};
int ipc_process_add (struct ipc_process_array *, struct ipc_client *);
int ipc_process_del (struct ipc_process_array *aproc, struct ipc_client *p);
void ipc_process_array_print (struct ipc_process_array *);
void ipc_process_array_free (struct ipc_process_array *);
struct ipc_client * ipc_server_process_copy (const struct ipc_client *p);
int ipc_server_process_eq (const struct ipc_client *p1, const struct ipc_client *p2);
// create the service process structure
void ipc_server_process_gen (struct ipc_client *p
, unsigned int index, unsigned int version);
void process_print (struct ipc_client *);
#endif

View File

@ -19,7 +19,7 @@ int main(int argc, char * argv[])
exit (1);
}
// read the message from the process
// read the message from the client
size_t mlen = 0;
unsigned char buf[BUFSIZ];
mlen = read (0, buf, BUFSIZ);

View File

@ -14,7 +14,7 @@ communication.h \- all functions explained
.sp
.BI "int ipc_server_close (struct ipc_service *" srv );
.BI "int ipc_server_close_proc (struct ipc_client *" p );
.BI "int ipc_server_select (struct ipc_process_array *" fds ", struct ipc_service *" srv ", struct ipc_process_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 " , const char *" service_name "
@ -46,29 +46,29 @@ The
.BR ipc_server_accept ()
function accepts new connections.
.IR p
parameter is the client process that will be provided after the connection.
parameter is the client client that will be provided after the connection.
.PP
The
.BR ipc_server_read ()
and
.BR ipc_server_write ()
functions take respectively a message to read from, and a message to write to a process.
functions take respectively a message to read from, and a message to write to a client.
.PP
The
.BR ipc_server_close_proc ()
and
.BR ipc_server_close ()
functions terminate respectively a process (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).
.PP
The
.BR ipc_server_select ()
takes three arguments,
.IR *ap
an array of processes you want to listen on,
an array of clientes you want to listen on,
.IR *srv
the service which receives new connections and
.IR *ap_read
an array of processes which have sent a message we need to read.
an array of clientes which have sent a message we need to read.
.PP
The
.BR ipc_application_connection ()
@ -108,4 +108,4 @@ Most of the functions return an integer less than zero if there is an error.
.PP
For
.BR ipc_server_select()
if there is a new connection, the function will return \fBCONNECTION\fR, if there is one or more processes talking the function will return \fBAPPLICATION\fR and finally if there are both a new connection and a process talking the function will return \fBCON_APP\fR.
if there is a new connection, the function will return \fBCONNECTION\fR, if there is one or more clientes talking the function will return \fBAPPLICATION\fR and finally if there are both a new connection and a client talking the function will return \fBCON_APP\fR.

View File

@ -1,5 +1,5 @@
#include "../../core/communication.h"
#include "../../core/process.h"
#include "../../core/client.h"
#include "../../core/error.h"
#include <sys/socket.h>
@ -10,7 +10,7 @@
int cpt = 0;
void handle_new_connection (struct ipc_service *srv, struct ipc_process_array *ap)
void handle_new_connection (struct ipc_service *srv, struct ipc_client_array *ap)
{
struct ipc_client *p = malloc(sizeof(struct ipc_client));
memset(p, 0, sizeof(struct ipc_client));
@ -21,15 +21,15 @@ void handle_new_connection (struct ipc_service *srv, struct ipc_process_array *a
printf("new connection\n");
}
if (ipc_process_add (ap, p) < 0) {
handle_error("ipc_process_add < 0");
if (ipc_client_add (ap, p) < 0) {
handle_error("ipc_client_add < 0");
}
cpt++;
printf ("%d client(s)\n", cpt);
}
void handle_new_msg (struct ipc_process_array *ap, struct ipc_process_array *proc_to_read)
void handle_new_msg (struct ipc_client_array *ap, struct ipc_client_array *proc_to_read)
{
struct ipc_message m;
memset (&m, 0, sizeof (struct ipc_message));
@ -40,17 +40,17 @@ void handle_new_msg (struct ipc_process_array *ap, struct ipc_process_array *pro
handle_error("server_read < 0");
}
// close the process then delete it from the process array
// close the client then delete it from the client array
if (m.type == MSG_TYPE_CLOSE) {
cpt--;
printf ("disconnection => %d client(s) remaining\n", cpt);
if (ipc_server_close_proc (proc_to_read->tab_proc[i]) < 0)
handle_err( "handle_new_msg", "server_close_proc < 0");
if (ipc_process_del (ap, proc_to_read->tab_proc[i]) < 0)
handle_err( "handle_new_msg", "ipc_process_del < 0");
if (ipc_process_del (proc_to_read, proc_to_read->tab_proc[i]) < 0)
handle_err( "handle_new_msg", "ipc_process_del < 0");
if (ipc_client_del (ap, proc_to_read->tab_proc[i]) < 0)
handle_err( "handle_new_msg", "ipc_client_del < 0");
if (ipc_client_del (proc_to_read, proc_to_read->tab_proc[i]) < 0)
handle_err( "handle_new_msg", "ipc_client_del < 0");
i--;
continue;
}
@ -74,16 +74,16 @@ void main_loop (struct ipc_service *srv)
{
int i, ret = 0;
struct ipc_process_array ap;
memset(&ap, 0, sizeof(struct ipc_process_array));
struct ipc_client_array ap;
memset(&ap, 0, sizeof(struct ipc_client_array));
struct ipc_process_array proc_to_read;
memset(&proc_to_read, 0, sizeof(struct ipc_process_array));
struct ipc_client_array proc_to_read;
memset(&proc_to_read, 0, sizeof(struct ipc_client_array));
while(1) {
ret = ipc_server_select (&ap, srv, &proc_to_read);
// printf ("on peut lire ces process:\n");
// ipc_process_array_print (&proc_to_read);
// printf ("on peut lire ces client:\n");
// ipc_client_array_print (&proc_to_read);
// printf ("-- \n\n");
if (ret == CONNECTION) {
@ -94,7 +94,7 @@ void main_loop (struct ipc_service *srv)
handle_new_connection (srv, &ap);
handle_new_msg (&ap, &proc_to_read);
}
ipc_process_array_free (&proc_to_read);
ipc_client_array_free (&proc_to_read);
}
for (i = 0; i < ap.size; i++) {

View File

@ -1,5 +1,5 @@
#include "../../core/communication.h"
#include "../../core/process.h"
#include "../../core/client.h"
#include "../../core/error.h"
#include "../lib/pubsubd.h"
#include <stdlib.h>

View File

@ -3,7 +3,7 @@
#include <string.h>
#include "../../core/error.h"
#include "../../core/process.h"
#include "../../core/client.h"
#include "channels.h"
@ -19,7 +19,7 @@ void pubsubd_channel_print (const struct channel *chan)
handle_err ("pubsubd_channel_print", "chan->subs == NULL");
}
else {
ipc_process_array_print (chan->subs);
ipc_client_array_print (chan->subs);
}
}
@ -98,8 +98,8 @@ int pubsubd_channel_new (struct channel *c, const char * name)
memcpy (c->chan, name, nlen);
c->chanlen = nlen;
c->subs = malloc (sizeof (struct ipc_process_array));
memset (c->subs, 0, sizeof (struct ipc_process_array));
c->subs = malloc (sizeof (struct ipc_client_array));
memset (c->subs, 0, sizeof (struct ipc_client_array));
return 0;
}
@ -115,7 +115,7 @@ void pubsubd_channel_free (struct channel * c)
}
if (c->subs != NULL) {
ipc_process_array_free (c->subs);
ipc_client_array_free (c->subs);
free (c->subs);
}
}
@ -154,12 +154,12 @@ int pubsubd_channel_eq (const struct channel *c1, const struct channel *c2)
void pubsubd_channel_subscribe (const struct channel *c, struct ipc_client *p)
{
ipc_process_add (c->subs, p);
ipc_client_add (c->subs, p);
}
void pubsubd_channel_unsubscribe (const struct channel *c, struct ipc_client *p)
{
ipc_process_del (c->subs, p);
ipc_client_del (c->subs, p);
}
void pubsubd_channels_subscribe (struct channels *chans

View File

@ -2,7 +2,7 @@
#define __CHANNELS_H__
#include "../../core/queue.h"
#include "../../core/process.h"
#include "../../core/client.h"
// head of the list
LIST_HEAD(channels, channel);
@ -12,7 +12,7 @@ LIST_HEAD(channels, channel);
struct channel {
char *chan;
size_t chanlen;
struct ipc_process_array *subs;
struct ipc_client_array *subs;
LIST_ENTRY(channel) entries;
};

View File

@ -2,7 +2,7 @@
#define __PUBSUB_H__
#include "../../core/communication.h"
#include "../../core/process.h"
#include "../../core/client.h"
#include "../../core/queue.h"
#include "msg.h"

View File

@ -1,6 +1,6 @@
#include "../../core/communication.h"
#include "../../core/msg.h"
#include "../../core/process.h"
#include "../../core/client.h"
#include "../../core/utils.h"
#include "../../core/error.h"
@ -11,7 +11,7 @@
#include <sys/un.h>
#include <unistd.h>
void pubsubd_send (const struct ipc_process_array *ap, const struct pubsub_msg * m)
void pubsubd_send (const struct ipc_client_array *ap, const struct pubsub_msg * m)
{
if (ap == NULL) {
fprintf (stderr, "pubsubd_send: ap == NULL");
@ -47,7 +47,7 @@ void pubsubd_send (const struct ipc_process_array *ap, const struct pubsub_msg *
// struct ipc_message m_data;
// memset (&m_data, 0, sizeof (struct ipc_message));
//
// // read the message from the process
// // read the message from the client
// ipc_server_read (p, &m_data);
//
// pubsub_message_unserialize (m, m_data.val, m_data.valsize);
@ -56,10 +56,10 @@ void pubsubd_send (const struct ipc_process_array *ap, const struct pubsub_msg *
// }
/**
* new connection, once accepted the process is added to the array_proc
* new connection, once accepted the client is added to the array_proc
* structure to be checked periodically for new messages
*/
void handle_new_connection (struct ipc_service *srv, struct ipc_process_array *ap)
void handle_new_connection (struct ipc_service *srv, struct ipc_client_array *ap)
{
struct ipc_client *p = malloc(sizeof(struct ipc_client));
memset(p, 0, sizeof(struct ipc_client));
@ -70,13 +70,13 @@ void handle_new_connection (struct ipc_service *srv, struct ipc_process_array *a
printf("new connection\n");
}
if (ipc_process_add (ap, p) < 0) {
handle_error("ipc_process_add < 0");
if (ipc_client_add (ap, p) < 0) {
handle_error("ipc_client_add < 0");
}
}
void handle_new_msg (struct channels *chans
, struct ipc_process_array *ap, struct ipc_process_array *proc_to_read)
, struct ipc_client_array *ap, struct ipc_client_array *proc_to_read)
{
struct ipc_message m;
memset (&m, 0, sizeof (struct ipc_message));
@ -89,7 +89,7 @@ void handle_new_msg (struct channels *chans
mprint_hexa ("msg received: ", (unsigned char *) m.val, m.valsize);
// close the process then delete it from the process array
// close the client then delete it from the client array
if (m.type == MSG_TYPE_CLOSE) {
struct ipc_client *p = proc_to_read->tab_proc[i];
@ -98,20 +98,20 @@ void handle_new_msg (struct channels *chans
// TODO: to test, unsubscribe when closing
pubsubd_channels_unsubscribe_everywhere (chans, p);
// close the connection to the process
// close the connection to the client
if (ipc_server_close_proc (p) < 0)
handle_error( "server_close_proc < 0");
// remove the process from the processes list
if (ipc_process_del (ap, p) < 0)
handle_error( "ipc_process_del < 0");
if (ipc_process_del (proc_to_read, p) < 0)
handle_err( "handle_new_msg", "ipc_process_del < 0");
// remove the client from the clientes list
if (ipc_client_del (ap, p) < 0)
handle_error( "ipc_client_del < 0");
if (ipc_client_del (proc_to_read, p) < 0)
handle_err( "handle_new_msg", "ipc_client_del < 0");
ipc_message_free (&m);
// free process
// free client
free (p);
i--;
@ -169,11 +169,11 @@ void pubsubd_main_loop (struct ipc_service *srv, struct channels *chans)
{
int i, ret = 0;
struct ipc_process_array ap;
memset(&ap, 0, sizeof(struct ipc_process_array));
struct ipc_client_array ap;
memset(&ap, 0, sizeof(struct ipc_client_array));
struct ipc_process_array proc_to_read;
memset(&proc_to_read, 0, sizeof(struct ipc_process_array));
struct ipc_client_array proc_to_read;
memset(&proc_to_read, 0, sizeof(struct ipc_client_array));
while(1) {
ret = ipc_server_select (&ap, srv, &proc_to_read);
@ -186,7 +186,7 @@ void pubsubd_main_loop (struct ipc_service *srv, struct channels *chans)
handle_new_connection (srv, &ap);
handle_new_msg (chans, &ap, &proc_to_read);
}
ipc_process_array_free (&proc_to_read);
ipc_client_array_free (&proc_to_read);
}
for (i = 0; i < ap.size; i++) {

View File

@ -2,7 +2,7 @@
#define __PUBSUBD_H__
// #include "../../core/pubsub.h"
#include "../../core/process.h"
#include "../../core/client.h"
#include "../../core/msg.h"
#include "msg.h"
#include "channels.h"
@ -10,6 +10,6 @@
#define PUBSUBD_SERVICE_NAME "pubsubd"
void pubsubd_main_loop (struct ipc_service *srv, struct channels * chans);
void pubsubd_message_send (const struct ipc_process_array *ap, const struct pubsub_msg * m);
void pubsubd_message_send (const struct ipc_client_array *ap, const struct pubsub_msg * m);
#endif

View File

@ -105,7 +105,7 @@ int pubsubd_worker_eq (const struct worker *w1, const struct worker *w2)
return w1 == w2; // if it's the same pointer
}
// a thread for each connected process
// a thread for each connected client
void * pubsubd_worker_thread (void *params)
{
int s = 0;
@ -132,7 +132,7 @@ void * pubsubd_worker_thread (void *params)
pubsub_message_recv (ale->p, &m);
if (m.type == PUBSUB_TYPE_DISCONNECT) {
// printf ("process %d disconnecting...\n", ale->p->pid);
// printf ("client %d disconnecting...\n", ale->p->pid);
if ( 0 != pubsubd_subscriber_del (chan->alh, ale)) {
fprintf (stderr, "err : subscriber not registered\n");
}

View File

@ -8,7 +8,7 @@
LIST_HEAD(workers, worker);
// element of the list
// worker : process to handle (threaded)
// worker : client to handle (threaded)
struct worker {
pthread_t *thr;
struct workers *my_workers;

View File

@ -5,7 +5,7 @@
#include "../lib/channels.h"
#include "../../core/error.h"
void fake_process (struct ipc_client *p
void fake_client (struct ipc_client *p
, unsigned int index, unsigned int version, int fake_fd)
{
p->version = version;
@ -85,10 +85,10 @@ void phase4 ()
struct channel * chan2 = pubsubd_channels_add (&chans, "chan2");
struct ipc_client proc1;
fake_process (&proc1, 0, 0, 1);
fake_client (&proc1, 0, 0, 1);
struct ipc_client proc2;
fake_process (&proc2, 0, 0, 2);
fake_client (&proc2, 0, 0, 2);
printf ("chan1: proc1, chan2: proc2\n");
pubsubd_channel_subscribe (chan1, &proc1);
@ -111,10 +111,10 @@ void phase5 ()
pubsubd_channels_add (&chans, "chan2");
struct ipc_client proc1;
fake_process (&proc1, 0, 0, 1);
fake_client (&proc1, 0, 0, 1);
struct ipc_client proc2;
fake_process (&proc2, 0, 0, 2);
fake_client (&proc2, 0, 0, 2);
printf ("chan1 & 2 => proc1 and 2 added\n");
pubsubd_channels_subscribe (&chans, "chan1", &proc1);

View File

@ -88,8 +88,8 @@ void sim_disconnection (int argc, char **argv, char **env, pid_t pid, int index,
struct ipc_client p;
memset (&p, 0, sizeof (struct ipc_client));
// create the fake process
ipc_server_process_gen (&p, pid, index, version);
// create the fake client
ipc_server_client_gen (&p, pid, index, version);
// send a message to disconnect
// line : pid index version action chan

View File

@ -1,5 +1,5 @@
#include "../../core/communication.h"
#include "../../core/process.h"
#include "../../core/client.h"
#include "../../core/error.h"
#include "../lib/remoted.h"
#include <stdlib.h>
@ -19,8 +19,8 @@ struct ipc_service srv;
void handle_signal (int signalnumber)
{
// the application will shut down, and remove the service unix socket
if (server_close (&srv) < 0) {
handle_error("server_close < 0");
if (ipc_server_close (&srv) < 0) {
handle_error("ipc_server_close < 0");
}
log_info ("remoted received a signal %d\n", signalnumber);
@ -95,7 +95,7 @@ int main(int argc, char **argv, char **env)
else
log_info ("remoted configuration loaded");
if (server_init (argc, argv, env, &srv, REMOTED_SERVICE_NAME) < 0) {
if (ipc_server_init (argc, argv, env, &srv, REMOTED_SERVICE_NAME) < 0) {
handle_error("server_init < 0");
}
log_info ("remoted listening on %s", srv.spath);
@ -106,7 +106,7 @@ int main(int argc, char **argv, char **env)
remoted_main_loop (&srv, &ctx);
// the application will shut down, and remove the service unix socket
if (server_close (&srv) < 0) {
if (ipc_server_close (&srv) < 0) {
handle_error("server_close < 0");
}
log_info ("remoted ended");

View File

@ -34,8 +34,8 @@ int remotec_message_send (struct ipc_service *srv, const struct remoted_msg * m)
memset (&m_data, 0, sizeof (struct ipc_message));
// format the connection msg
if (msg_format_data (&m_data, buf, msize) < 0) {
handle_err ("remotec_message_send", "msg_format_data");
if (ipc_message_format_data (&m_data, buf, msize) < 0) {
handle_err ("remotec_message_send", "ipc_message_format_data");
if (buf != NULL)
free (buf);
return -1;

View File

@ -1,7 +1,7 @@
#ifndef __REMOTEC_H__
#define __REMOTEC_H__
#include "../../core/process.h"
#include "../../core/client.h"
#include "../../core/msg.h"
#include "remoted.h"

View File

@ -1,6 +1,6 @@
#include "../../core/communication.h"
#include "../../core/msg.h"
#include "../../core/process.h"
#include "../../core/client.h"
#include "../../core/utils.h"
#include "../../core/error.h"
#include "../../core/logger.h"
@ -12,56 +12,56 @@
#include <unistd.h>
/**
* new connection, once accepted the process is added to the array_proc
* new connection, once accepted the client is added to the array_proc
* structure to be checked periodically for new messages
*/
void handle_new_connection (struct ipc_service *srv, struct ipc_process_array *ap)
void handle_new_connection (struct ipc_service *srv, struct ipc_client_array *ap)
{
struct ipc_client *p = malloc(sizeof(struct ipc_client));
memset(p, 0, sizeof(struct ipc_client));
if (server_accept (srv, p) < 0) {
handle_error("server_accept < 0");
if (ipc_server_accept (srv, p) < 0) {
handle_error("ipc_server_accept < 0");
} else {
log_debug ("remoted, new connection", p->proc_fd);
}
if (ipc_process_add (ap, p) < 0) {
handle_error("ipc_process_add < 0");
if (ipc_client_add (ap, p) < 0) {
handle_error("ipc_client_add < 0");
}
}
void handle_new_msg (struct ipc_process_array *ap, struct ipc_process_array *proc_to_read)
void handle_new_msg (struct ipc_client_array *ap, struct ipc_client_array *proc_to_read)
{
struct ipc_message m;
memset (&m, 0, sizeof (struct ipc_message));
int i;
for (i = 0; i < proc_to_read->size; i++) {
if (server_read (proc_to_read->tab_proc[i], &m) < 0) {
handle_error("server_read < 0");
if (ipc_server_read (proc_to_read->tab_proc[i], &m) < 0) {
handle_error("ipc_server_read < 0");
}
mprint_hexa ("msg received: ", (unsigned char *) m.val, m.valsize);
// close the process then delete it from the process array
// close the client then delete it from the client array
if (m.type == MSG_TYPE_CLOSE) {
struct ipc_client *p = proc_to_read->tab_proc[i];
log_debug ("remoted, proc %d disconnecting", p->proc_fd);
// close the connection to the process
if (server_close_proc (p) < 0)
handle_error( "server_close_proc < 0");
// close the connection to the client
if (ipc_server_close_proc (p) < 0)
handle_error( "ipc_server_close_proc < 0");
// remove the process from the processes list
if (ipc_process_del (ap, p) < 0)
handle_error( "ipc_process_del < 0");
if (ipc_process_del (proc_to_read, p) < 0)
handle_err( "handle_new_msg", "ipc_process_del < 0");
// remove the client from the clientes list
if (ipc_client_del (ap, p) < 0)
handle_error( "ipc_client_del < 0");
if (ipc_client_del (proc_to_read, p) < 0)
handle_err( "handle_new_msg", "ipc_client_del < 0");
ipc_message_free (&m);
// free process
// free client
free (p);
i--;
@ -114,11 +114,11 @@ void remoted_main_loop (struct ipc_service *srv, struct remoted_ctx *ctx)
log_debug ("remoted entering main loop");
int i, ret = 0;
struct ipc_process_array ap;
memset(&ap, 0, sizeof(struct ipc_process_array));
struct ipc_client_array ap;
memset(&ap, 0, sizeof(struct ipc_client_array));
struct ipc_process_array proc_to_read;
memset(&proc_to_read, 0, sizeof(struct ipc_process_array));
struct ipc_client_array proc_to_read;
memset(&proc_to_read, 0, sizeof(struct ipc_client_array));
while(1) {
/* TODO: authorizations */
@ -132,12 +132,12 @@ void remoted_main_loop (struct ipc_service *srv, struct remoted_ctx *ctx)
handle_new_connection (srv, &ap);
handle_new_msg (&ap, &proc_to_read);
}
ipc_process_array_free (&proc_to_read);
ipc_client_array_free (&proc_to_read);
}
for (i = 0; i < ap.size; i++) {
if (server_close_proc (ap.tab_proc[i]) < 0) {
handle_error( "server_close_proc < 0");
if (ipc_server_close_proc (ap.tab_proc[i]) < 0) {
handle_error( "ipc_server_close_proc < 0");
}
}
}

View File

@ -1,7 +1,7 @@
#ifndef __REMOTED_H__
#define __REMOTED_H__
#include "../../core/process.h"
#include "../../core/client.h"
#include "../../core/msg.h"
#include "msg.h"

View File

@ -134,7 +134,7 @@ void * service_thread(void * c_data) {
/*struct ipc_client p;
ipc_application_create(&p, getpid(), cda->index, version);
ipc_server_process_print(&p);*/
ipc_server_client_print(&p);*/
//sleep(1);
//printf("%s\n",p.path_proc );
/*if (proc_connection(&p) == -1){
@ -303,7 +303,7 @@ void * ipc_server_thread(void * reqq) {
/* something from standard input : i.e keyboard */
if(FD_ISSET(STDIN_FILENO, &rdfs))
{
/* stop process when type on keyboard */
/* stop client when type on keyboard */
for (i = 0; i < actual; i++) {
if (pthread_cancel(tab_service_threads[i]) != 0) {
printf("Aucun thread correspond \n");
@ -401,7 +401,7 @@ int ipc_server_get_new_request(char *buf, info_request *req) {
req->addr.sin_family = AF_INET;
if (strcmp("connect", req->request) == 0) {
ipc_server_process_gen (req->p, pid, index, version);
ipc_server_client_gen (req->p, pid, index, version);
}
return 1;
@ -664,7 +664,7 @@ void main_loop (struct ipc_service *srv) {
}
tab_req[nbclient].p = malloc(sizeof(struct ipc_client));
// -1 : error, 0 = no new process, 1 = new process
// -1 : error, 0 = no new client, 1 = new client
ret = ipc_server_get_new_request (buf, &tab_req[nbclient]);
tab_req[nbclient].p->proc_fd = newfd;
if (ret == -1) {
@ -715,7 +715,7 @@ void main_loop (struct ipc_service *srv) {
}
tab_req[nbclient].p = malloc(sizeof(struct ipc_client));
// -1 : error, 0 = no new process, 1 = new process
// -1 : error, 0 = no new client, 1 = new client
ret = ipc_server_get_new_request (buf, &tab_req[nbclient]);
tab_req[nbclient].p->proc_fd = i;
if (ret == -1) {