Archived
3
0

cleaning names

This commit is contained in:
Philippe PITTOLI 2018-10-03 21:24:20 +02:00
parent 7305833c6a
commit 3eeb96b21d
21 changed files with 203 additions and 204 deletions

View File

@ -22,8 +22,8 @@ int main (int argc, char *argv[], char *env[])
srv.version = 0; srv.version = 0;
// init service // init service
if (app_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) { if (application_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) {
handle_err("main", "srv_init < 0"); handle_err("main", "server_init < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -31,22 +31,22 @@ int main (int argc, char *argv[], char *env[])
msg_format_data (&m, MSG, strlen(MSG) +1); msg_format_data (&m, MSG, strlen(MSG) +1);
printf ("msg to send in the client: "); printf ("msg to send in the client: ");
print_msg (&m); print_msg (&m);
if (app_write (&srv, &m) < 0) { if (application_write (&srv, &m) < 0) {
handle_err("main", "app_write < 0"); handle_err("main", "application_write < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
msg_free (&m); msg_free (&m);
if (app_read (&srv, &m) < 0) { if (application_read (&srv, &m) < 0) {
handle_err("main", "app_read < 0"); handle_err("main", "application_read < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf ("msg recv: %s\n", m.val); printf ("msg recv: %s\n", m.val);
msg_free (&m); msg_free (&m);
if (app_close (&srv) < 0) { if (application_close (&srv) < 0) {
handle_err("main", "app_close < 0"); handle_err("main", "application_close < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -24,32 +24,32 @@ int main (int argc, char *argv[], char *env[])
memset (&p, 0, sizeof (struct process)); memset (&p, 0, sizeof (struct process));
// init service // init service
if (srv_init (argc, argv, env, &srv, SERVICE_NAME) < 0) { if (server_init (argc, argv, env, &srv, SERVICE_NAME) < 0) {
handle_err("main", "srv_init < 0"); handle_err("main", "server_init < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (srv_accept (&srv, &p) < 0) { if (server_accept (&srv, &p) < 0) {
handle_err("main", "srv_accept < 0"); handle_err("main", "server_accept < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (srv_read (&p, &m) < 0) { if (server_read (&p, &m) < 0) {
handle_err("main", "srv_read < 0"); handle_err("main", "server_read < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf ("msg recv: %s\n", m.val); printf ("msg recv: %s\n", m.val);
if (srv_write (&p, &m) < 0) { if (server_write (&p, &m) < 0) {
handle_err("main", "srv_write < 0"); handle_err("main", "server_write < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
msg_free (&m); msg_free (&m);
// client quits // client quits
if (srv_read (&p, &m) < 0) { if (server_read (&p, &m) < 0) {
handle_err("main", "srv_read < 0"); handle_err("main", "server_read < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (m.type == MSG_TYPE_CLOSE) { if (m.type == MSG_TYPE_CLOSE) {
@ -60,13 +60,13 @@ int main (int argc, char *argv[], char *env[])
} }
msg_free (&m); msg_free (&m);
if (srv_close_proc (&p) < 0) { if (server_close_proc (&p) < 0) {
handle_err("main", "srv_close_proc < 0"); handle_err("main", "server_close_proc < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (srv_close (&srv) < 0) { if (server_close (&srv) < 0) {
handle_err("main", "srv_close < 0"); handle_err("main", "server_close < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -15,7 +15,7 @@ void service_path (char *path, const char *sname, int index, int version)
snprintf (path, PATH_MAX, "%s/%s-%d-%d", TMPDIR, sname, index, version); snprintf (path, PATH_MAX, "%s/%s-%d-%d", TMPDIR, sname, index, version);
} }
int srv_init (int argc, char **argv, char **env int ipc_server_init (int argc, char **argv, char **env
, struct service *srv, const char *sname) , struct service *srv, const char *sname)
{ {
if (srv == NULL) if (srv == NULL)
@ -37,7 +37,7 @@ int srv_init (int argc, char **argv, char **env
return usock_init (&srv->service_fd, srv->spath); return usock_init (&srv->service_fd, srv->spath);
} }
int srv_accept (struct service *srv, struct process *p) int ipc_server_accept (struct service *srv, struct process *p)
{ {
assert (srv != NULL); assert (srv != NULL);
assert (p != NULL); assert (p != NULL);
@ -46,49 +46,49 @@ int srv_accept (struct service *srv, struct process *p)
struct msg m_con; struct msg m_con;
memset (&m_con, 0, sizeof (struct msg)); memset (&m_con, 0, sizeof (struct msg));
srv_read (p, &m_con); ipc_server_read (p, &m_con);
// TODO: handle the parameters in the first message // TODO: handle the parameters in the first message
msg_free (&m_con); msg_free (&m_con);
struct msg m_ack; struct msg m_ack;
memset (&m_ack, 0, sizeof (struct msg)); memset (&m_ack, 0, sizeof (struct msg));
msg_format_ack (&m_ack, NULL, 0); msg_format_ack (&m_ack, NULL, 0);
srv_write (p, &m_ack); ipc_server_write (p, &m_ack);
msg_free (&m_ack); msg_free (&m_ack);
return 0; return 0;
} }
int srv_close (struct service *srv) int ipc_server_close (struct service *srv)
{ {
usock_close (srv->service_fd); usock_close (srv->service_fd);
return usock_remove (srv->spath); return usock_remove (srv->spath);
} }
int srv_close_proc (struct process *p) int ipc_server_close_proc (struct process *p)
{ {
// struct msg m_ack_dis; // struct msg m_ack_dis;
// memset (&m_ack_dis, 0, sizeof (struct msg)); // memset (&m_ack_dis, 0, sizeof (struct msg));
// m_ack_dis.type = MSG_TYPE_CLOSE; // m_ack_dis.type = MSG_TYPE_CLOSE;
// if (msg_write (p->proc_fd, &m_ack_dis) < 0) { // if (msg_write (p->proc_fd, &m_ack_dis) < 0) {
// handle_err ("srv_close_proc", "msg_write < 0"); // handle_err ("server_close_proc", "msg_write < 0");
// } // }
return usock_close (p->proc_fd); return usock_close (p->proc_fd);
} }
int srv_read (const struct process *p, struct msg *m) int ipc_server_read (const struct process *p, struct msg *m)
{ {
return msg_read (p->proc_fd, m); return msg_read (p->proc_fd, m);
} }
int srv_write (const struct process *p, const struct msg *m) int ipc_server_write (const struct process *p, const struct msg *m)
{ {
return msg_write (p->proc_fd, m); return msg_write (p->proc_fd, m);
} }
int app_connection (int argc, char **argv, char **env int ipc_application_connection (int argc, char **argv, char **env
, struct service *srv, const char *sname , struct service *srv, const char *sname
, const char *connectionstr, size_t msize) , const char *connectionstr, size_t msize)
{ {
@ -114,18 +114,18 @@ int app_connection (int argc, char **argv, char **env
// format the connection msg // format the connection msg
if (msg_format_con (&m_con, connectionstr, msize) < 0) { if (msg_format_con (&m_con, connectionstr, msize) < 0) {
handle_err ("app_connection", "msg_format_con"); handle_err ("application_connection", "msg_format_con");
return -1; return -1;
} }
// send connection msg // send connection msg
app_write (srv, &m_con); ipc_application_write (srv, &m_con);
msg_free (&m_con); msg_free (&m_con);
// receive ack msg // receive ack msg
struct msg m_ack; struct msg m_ack;
memset (&m_ack, 0, sizeof (struct msg)); memset (&m_ack, 0, sizeof (struct msg));
app_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.valsize == 0);
@ -135,24 +135,24 @@ int app_connection (int argc, char **argv, char **env
} }
// send a CLOSE message then close the socket // send a CLOSE message then close the socket
int app_close (struct service *srv) int ipc_application_close (struct service *srv)
{ {
struct msg m; struct msg m;
memset (&m, 0, sizeof (struct msg)); memset (&m, 0, sizeof (struct msg));
m.type = MSG_TYPE_CLOSE; m.type = MSG_TYPE_CLOSE;
if (msg_write (srv->service_fd, &m) < 0) { if (msg_write (srv->service_fd, &m) < 0) {
handle_err ("app_close", "msg_write < 0"); handle_err ("application_close", "msg_write < 0");
} }
return usock_close (srv->service_fd); return usock_close (srv->service_fd);
} }
int app_read (struct service *srv, struct msg *m) int ipc_application_read (struct service *srv, struct msg *m)
{ {
return msg_read (srv->service_fd, m); return msg_read (srv->service_fd, m);
} }
int app_write (struct service *srv, const struct msg *m) int ipc_application_write (struct service *srv, const struct msg *m)
{ {
return msg_write (srv->service_fd, m); return msg_write (srv->service_fd, m);
} }
@ -175,7 +175,7 @@ int getMaxFd(struct array_proc *ap)
} }
/* /*
* srv_select prend en parametre * ipc_server_select prend en parametre
* * un tableau de process qu'on écoute * * un tableau de process qu'on écoute
* * le service qui attend de nouvelles connexions * * le service qui attend de nouvelles connexions
* * un tableau de process qui souhaitent parler * * un tableau de process qui souhaitent parler
@ -187,7 +187,7 @@ int getMaxFd(struct array_proc *ap)
* * les deux à la fois (CON_APP) * * les deux à la fois (CON_APP)
*/ */
int srv_select (struct array_proc *ap, struct service *srv int ipc_server_select (struct array_proc *ap, struct service *srv
, struct array_proc *proc) , struct array_proc *proc)
{ {
assert (ap != NULL); assert (ap != NULL);
@ -222,7 +222,7 @@ int srv_select (struct array_proc *ap, struct service *srv
int is_listener = 0; int is_listener = 0;
do { do {
// printf ("loop srv_select main_loop\n"); // printf ("loop ipc_server_select main_loop\n");
readf = master; readf = master;
if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) { if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) {
perror("select"); perror("select");
@ -231,13 +231,13 @@ int srv_select (struct array_proc *ap, struct service *srv
/*run through the existing connections looking for data to be read*/ /*run through the existing connections looking for data to be read*/
for (i = 0; i <= fdmax; i++) { for (i = 0; i <= fdmax; i++) {
// printf ("loop srv_select inner loop\n"); // printf ("loop ipc_server_select inner loop\n");
if (FD_ISSET(i, &readf)) { if (FD_ISSET(i, &readf)) {
if (i == listener) { if (i == listener) {
is_listener = 1; is_listener = 1;
} else { } else {
for(j = 0; j < ap->size; j++) { for(j = 0; j < ap->size; j++) {
// printf ("loop srv_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->tab_proc[j]->proc_fd ) {
add_proc (proc, ap->tab_proc[j]); add_proc (proc, ap->tab_proc[j]);
} }

View File

@ -14,7 +14,7 @@
#define ER_MEM_ALLOC 100 #define ER_MEM_ALLOC 100
#define ER_PARAMS 101 #define ER_PARAMS 101
#define TMPDIR "/tmp/ipc/" #define TMPDIR "/run/ipc/"
#define PATH_MAX BUFSIZ #define PATH_MAX BUFSIZ
@ -34,28 +34,28 @@ struct service {
// srv->version and srv->index must be already set // srv->version and srv->index must be already set
// init unix socket + fill srv->spath // init unix socket + fill srv->spath
int srv_init (int argc, char **argv, char **env int ipc_server_init (int argc, char **argv, char **env
, struct service *srv, const char *sname); , struct service *srv, const char *sname);
int srv_close (struct service *srv); int ipc_server_close (struct service *srv);
int srv_close_proc (struct process *p); int ipc_server_close_proc (struct process *p);
int srv_accept (struct service *srv, struct process *p); int ipc_server_accept (struct service *srv, struct process *p);
int srv_read (const struct process *, struct msg *m); int ipc_server_read (const struct process *, struct msg *m);
int srv_write (const struct process *, const struct msg *m); int ipc_server_write (const struct process *, const struct msg *m);
int srv_select (struct array_proc *, struct service *, struct array_proc *); int ipc_server_select (struct array_proc *, struct service *, struct array_proc *);
// APPLICATION // APPLICATION
// Initialize connection with unix socket // Initialize connection with unix socket
// send the connection string to $TMP/<service> // send the connection string to $TMP/<service>
// fill srv->spath && srv->service_fd // fill srv->spath && srv->service_fd
int app_connection (int argc, char **argv, char **env int ipc_application_connection (int argc, char **argv, char **env
, struct service *, const char *, const char *, size_t); , struct service *, const char *, const char *, size_t);
int app_close (struct service *); int ipc_application_close (struct service *);
int app_read (struct service *srv, struct msg *m); int ipc_application_read (struct service *srv, struct msg *m);
int app_write (struct service *, const struct msg *m); int ipc_application_write (struct service *, const struct msg *m);

View File

@ -5,7 +5,7 @@
#include <string.h> #include <string.h>
struct process * srv_process_copy (const struct process *p) struct process * server_process_copy (const struct process *p)
{ {
if (p == NULL) if (p == NULL)
return NULL; return NULL;
@ -16,13 +16,13 @@ struct process * srv_process_copy (const struct process *p)
return copy; return copy;
} }
int srv_process_eq (const struct process *p1, const struct process *p2) int server_process_eq (const struct process *p1, const struct process *p2)
{ {
return (p1->version == p2->version && p1->index == p2->index return (p1->version == p2->version && p1->index == p2->index
&& p1->proc_fd == p2->proc_fd); && p1->proc_fd == p2->proc_fd);
} }
void srv_process_gen (struct process *p void server_process_gen (struct process *p
, unsigned int index, unsigned int version) , unsigned int index, unsigned int version)
{ {
p->version = version; p->version = version;

View File

@ -18,10 +18,10 @@ int del_proc (struct array_proc *aproc, struct process *p);
void array_proc_print (struct array_proc *); void array_proc_print (struct array_proc *);
void array_proc_free (struct array_proc *); void array_proc_free (struct array_proc *);
struct process * srv_process_copy (const struct process *p); struct process * server_process_copy (const struct process *p);
int srv_process_eq (const struct process *p1, const struct process *p2); int server_process_eq (const struct process *p1, const struct process *p2);
// create the service process structure // create the service process structure
void srv_process_gen (struct process *p void server_process_gen (struct process *p
, unsigned int index, unsigned int version); , unsigned int index, unsigned int version);
void process_print (struct process *); void process_print (struct process *);

View File

@ -12,11 +12,11 @@ int main(int argc, char * argv[], char *env[])
{ {
struct service srv; struct service srv;
memset (&srv, 0, sizeof (struct service)); memset (&srv, 0, sizeof (struct service));
srv_init (argc, argv, env, &srv, SERVICE, NULL); server_init (argc, argv, env, &srv, SERVICE, NULL);
printf ("Listening on %s.\n", srv.spath); printf ("Listening on %s.\n", srv.spath);
// creates the service named pipe, that listens to client applications // creates the service named pipe, that listens to client applications
if (srv_create (&srv)) if (server_create (&srv))
ohshit(1, "service_create error"); ohshit(1, "service_create error");
/* /*
@ -30,8 +30,8 @@ int main(int argc, char * argv[], char *env[])
int version = 1; int version = 1;
printf ("app creation\n"); printf ("app creation\n");
if (app_create (&p, index, version)) // called by the application if (application_create (&p, index, version)) // called by the application
ohshit (1, "app_create"); ohshit (1, "application_create");
/* /*
* some exchanges between App and S * some exchanges between App and S
@ -41,16 +41,16 @@ int main(int argc, char * argv[], char *env[])
printf ("destroying app\n"); printf ("destroying app\n");
// the application will shut down, and remove the application named pipes // the application will shut down, and remove the application named pipes
if (app_destroy (&p)) if (application_destroy (&p))
ohshit (1, "app_destroy"); ohshit (1, "application_destroy");
/* /*
* /PROCESS * /PROCESS
*/ */
// the application will shut down, and remove the service named pipe // the application will shut down, and remove the service named pipe
if (srv_close (&srv)) if (server_close (&srv))
ohshit (1, "srv_close error"); ohshit (1, "server_close error");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -5,31 +5,31 @@ communication.h \- all functions explained
.nf .nf
.B #include <communication.h> .B #include <communication.h>
.sp .sp
.BI "int srv_init (int "argc ", char **" argv ", char **" env ", struct service *" srv " .BI "int server_init (int "argc ", char **" argv ", char **" env ", struct service *" srv "
.BI " , const char *" service_name ); .BI " , const char *" service_name );
.BI "int srv_accept (struct service *" srv ", struct process *" p ); .BI "int server_accept (struct service *" srv ", struct process *" p );
.sp .sp
.BI "int srv_read (const struct process *" p ", struct msg *" message ); .BI "int server_read (const struct process *" p ", struct msg *" message );
.BI "int srv_write (const struct process *" p ", const struct msg *" message ); .BI "int server_write (const struct process *" p ", const struct msg *" message );
.sp .sp
.BI "int srv_close (struct service *" srv ); .BI "int server_close (struct service *" srv );
.BI "int srv_close_proc (struct process *" p ); .BI "int server_close_proc (struct process *" p );
.BI "int srv_select (struct array_proc *" fds ", struct service *" srv ", struct array_proc *" readfds ); .BI "int server_select (struct array_proc *" fds ", struct service *" srv ", struct array_proc *" readfds );
.BI "int app_connection (int " argc ", char **" argv ", char **" env ", struct service *" srv .BI "int application_connection (int " argc ", char **" argv ", char **" env ", struct service *" srv
.BI " , const char *" service_name " .BI " , const char *" service_name "
.BI " , const char *" connection_buffer ", size_t " bufsize ); .BI " , const char *" connection_buffer ", size_t " bufsize );
.sp .sp
.BI "int app_read (const struct service *" srv ", struct msg *" message ); .BI "int application_read (const struct service *" srv ", struct msg *" message );
.BI "int app_write (const struct service *" srv ", const struct msg *" message ); .BI "int application_write (const struct service *" srv ", const struct msg *" message );
.sp .sp
.BI "int app_close (struct service *" srv ); .BI "int application_close (struct service *" srv );
.fi .fi
.SH DESCRIPTION .SH DESCRIPTION
The The
.BR srv_init () .BR server_init ()
function let the service declare itself, create a new unix socket and listen. function let the service declare itself, create a new unix socket and listen.
.I argc .I argc
, ,
@ -40,28 +40,28 @@ should be passed to the function in order to automatically change the behavior o
.I *srv .I *srv
is the pointer to the \fBstruct service\fR that should be filled (index and version parameters). is the pointer to the \fBstruct service\fR that should be filled (index and version parameters).
The \fBsrv_init()\fR function will fill the rest of the elements of this structure, such as the unix socket path and the unix socket file descriptor in order to be able to receive new connections. The \fBserver_init()\fR function will fill the rest of the elements of this structure, such as the unix socket path and the unix socket file descriptor in order to be able to receive new connections.
.PP .PP
The The
.BR srv_accept () .BR server_accept ()
function accepts new connections. function accepts new connections.
.IR p .IR p
parameter is the client process that will be provided after the connection. parameter is the client process that will be provided after the connection.
.PP .PP
The The
.BR srv_read () .BR server_read ()
and and
.BR srv_write () .BR 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 process.
.PP .PP
The The
.BR srv_close_proc () .BR server_close_proc ()
and and
.BR srv_close () .BR 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 process (closing its unix socket) and the service (closing and removing its named unix socket).
.PP .PP
The The
.BR srv_select () .BR server_select ()
takes three arguments, takes three arguments,
.IR *ap .IR *ap
an array of processes you want to listen on, an array of processes you want to listen on,
@ -71,7 +71,7 @@ the service which receives new connections and
an array of processes which have sent a message we need to read. an array of processes which have sent a message we need to read.
.PP .PP
The The
.BR app_connection () .BR application_connection ()
function takes function takes
.I argc .I argc
, ,
@ -95,17 +95,17 @@ The function finally connects itself to the service.
\fBIn a near future, this function will be completed to invoke transparently the remote service\fR. \fBIn a near future, this function will be completed to invoke transparently the remote service\fR.
.PP .PP
The The
.BR app_read () .BR application_read ()
and and
.BR app_write () .BR application_write ()
functions take respectively a message to read from, and a message to write to the service. functions take respectively a message to read from, and a message to write to the service.
.PP .PP
The The
.BR app_close () .BR application_close ()
function finally ends the communication to the service. function finally ends the communication to the service.
.SH RETURN VALUE .SH RETURN VALUE
Most of the functions return an integer less than zero if there is an error. Most of the functions return an integer less than zero if there is an error.
.PP .PP
For For
.BR srv_select() .BR 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 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.

View File

@ -22,8 +22,8 @@ void non_interactive (int argc, char *argv[], char *env[])
srv.version = 0; srv.version = 0;
// init service // init service
if (app_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) { if (ipc_application_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) {
handle_err("main", "srv_init < 0"); handle_err("main", "server_init < 0");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -31,22 +31,22 @@ void non_interactive (int argc, char *argv[], char *env[])
msg_format_data (&m, MSG, strlen(MSG) +1); msg_format_data (&m, MSG, strlen(MSG) +1);
printf ("msg to send in the client: "); printf ("msg to send in the client: ");
print_msg (&m); print_msg (&m);
if (app_write (&srv, &m) < 0) { if (ipc_application_write (&srv, &m) < 0) {
handle_err("main", "app_write < 0"); handle_err("main", "application_write < 0");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
msg_free (&m); msg_free (&m);
if (app_read (&srv, &m) < 0) { if (ipc_application_read (&srv, &m) < 0) {
handle_err("main", "app_read < 0"); handle_err("main", "application_read < 0");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
printf ("msg recv: %s\n", m.val); printf ("msg recv: %s\n", m.val);
msg_free (&m); msg_free (&m);
if (app_close (&srv) < 0) { if (ipc_application_close (&srv) < 0) {
handle_err("main", "app_close < 0"); handle_err("main", "application_close < 0");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} }
@ -67,8 +67,8 @@ void interactive (int argc, char *argv[], char *env[])
srv.version = 0; srv.version = 0;
// init service // init service
if (app_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) { if (ipc_application_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) {
handle_err ("main", "srv_init < 0"); handle_err ("main", "server_init < 0");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -85,14 +85,14 @@ void interactive (int argc, char *argv[], char *env[])
// print_msg (&m); // print_msg (&m);
if (app_write (&srv, &m) < 0) { if (ipc_application_write (&srv, &m) < 0) {
handle_err("main", "app_write < 0"); handle_err("main", "application_write < 0");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
msg_free (&m); msg_free (&m);
if (app_read (&srv, &m) < 0) { if (ipc_application_read (&srv, &m) < 0) {
handle_err("main", "app_read < 0"); handle_err("main", "application_read < 0");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -100,8 +100,8 @@ void interactive (int argc, char *argv[], char *env[])
msg_free (&m); msg_free (&m);
} }
if (app_close (&srv) < 0) { if (ipc_application_close (&srv) < 0) {
handle_err("main", "app_close < 0"); handle_err("main", "application_close < 0");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} }

View File

@ -15,8 +15,8 @@ void handle_new_connection (struct service *srv, struct array_proc *ap)
struct process *p = malloc(sizeof(struct process)); struct process *p = malloc(sizeof(struct process));
memset(p, 0, sizeof(struct process)); memset(p, 0, sizeof(struct process));
if (srv_accept (srv, p) < 0) { if (ipc_server_accept (srv, p) < 0) {
handle_error("srv_accept < 0"); handle_error("server_accept < 0");
} else { } else {
printf("new connection\n"); printf("new connection\n");
} }
@ -36,8 +36,8 @@ void handle_new_msg (struct array_proc *ap, struct array_proc *proc_to_read)
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 (srv_read (proc_to_read->tab_proc[i], &m) < 0) { if (ipc_server_read (proc_to_read->tab_proc[i], &m) < 0) {
handle_error("srv_read < 0"); handle_error("server_read < 0");
} }
// close the process then delete it from the process array // close the process then delete it from the process array
@ -45,8 +45,8 @@ void handle_new_msg (struct array_proc *ap, struct array_proc *proc_to_read)
cpt--; cpt--;
printf ("disconnection => %d client(s) remaining\n", cpt); printf ("disconnection => %d client(s) remaining\n", cpt);
if (srv_close_proc (proc_to_read->tab_proc[i]) < 0) if (ipc_server_close_proc (proc_to_read->tab_proc[i]) < 0)
handle_err( "handle_new_msg", "srv_close_proc < 0"); handle_err( "handle_new_msg", "server_close_proc < 0");
if (del_proc (ap, proc_to_read->tab_proc[i]) < 0) if (del_proc (ap, proc_to_read->tab_proc[i]) < 0)
handle_err( "handle_new_msg", "del_proc < 0"); handle_err( "handle_new_msg", "del_proc < 0");
if (del_proc (proc_to_read, proc_to_read->tab_proc[i]) < 0) if (del_proc (proc_to_read, proc_to_read->tab_proc[i]) < 0)
@ -56,8 +56,8 @@ void handle_new_msg (struct array_proc *ap, struct array_proc *proc_to_read)
} }
printf ("new message : %s", m.val); printf ("new message : %s", m.val);
if (srv_write (proc_to_read->tab_proc[i], &m) < 0) { if (ipc_server_write (proc_to_read->tab_proc[i], &m) < 0) {
handle_err( "handle_new_msg", "srv_write < 0"); handle_err( "handle_new_msg", "server_write < 0");
} }
} }
} }
@ -81,7 +81,7 @@ void main_loop (struct service *srv)
memset(&proc_to_read, 0, sizeof(struct array_proc)); memset(&proc_to_read, 0, sizeof(struct array_proc));
while(1) { while(1) {
ret = srv_select (&ap, srv, &proc_to_read); ret = ipc_server_select (&ap, srv, &proc_to_read);
// printf ("on peut lire ces process:\n"); // printf ("on peut lire ces process:\n");
// array_proc_print (&proc_to_read); // array_proc_print (&proc_to_read);
// printf ("-- \n\n"); // printf ("-- \n\n");
@ -98,8 +98,8 @@ void main_loop (struct service *srv)
} }
for (i = 0; i < ap.size; i++) { for (i = 0; i < ap.size; i++) {
if (srv_close_proc (ap.tab_proc[i]) < 0) { if (ipc_server_close_proc (ap.tab_proc[i]) < 0) {
handle_error( "srv_close_proc < 0"); handle_error( "server_close_proc < 0");
} }
} }
} }
@ -124,8 +124,8 @@ int main(int argc, char * argv[], char **env)
// unlink("/tmp/ipc/pongd-0-0"); // unlink("/tmp/ipc/pongd-0-0");
if (srv_init (argc, argv, env, &srv, PONGD_SERVICE_NAME) < 0) { if (ipc_server_init (argc, argv, env, &srv, PONGD_SERVICE_NAME) < 0) {
handle_error("srv_init < 0"); handle_error("server_init < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf ("Listening on %s.\n", srv.spath); printf ("Listening on %s.\n", srv.spath);
@ -136,8 +136,8 @@ int main(int argc, char * argv[], char **env)
main_loop (&srv); main_loop (&srv);
// the application will shut down, and remove the service named pipe // the application will shut down, and remove the service named pipe
if (srv_close (&srv) < 0) { if (ipc_server_close (&srv) < 0) {
handle_error("srv_close < 0"); handle_error("server_close < 0");
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -16,8 +16,8 @@ struct channels chans;
void handle_signal (int signalnumber) void handle_signal (int signalnumber)
{ {
// the application will shut down, and remove the service named pipe // the application will shut down, and remove the service named pipe
if (srv_close (&srv) < 0) { if (server_close (&srv) < 0) {
handle_error("srv_close < 0"); handle_error("server_close < 0");
} }
pubsubd_channels_del_all (&chans); pubsubd_channels_del_all (&chans);
@ -40,8 +40,8 @@ main(int argc, char **argv, char **env)
memset (&chans, 0, sizeof (struct channels)); memset (&chans, 0, sizeof (struct channels));
pubsubd_channels_init (&chans); pubsubd_channels_init (&chans);
if (srv_init (argc, argv, env, &srv, PUBSUBD_SERVICE_NAME) < 0) { if (server_init (argc, argv, env, &srv, PUBSUBD_SERVICE_NAME) < 0) {
handle_error("srv_init < 0"); handle_error("server_init < 0");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf ("Listening on %s.\n", srv.spath); printf ("Listening on %s.\n", srv.spath);
@ -52,8 +52,8 @@ main(int argc, char **argv, char **env)
pubsubd_main_loop (&srv, &chans); pubsubd_main_loop (&srv, &chans);
// the application will shut down, and remove the service named pipe // the application will shut down, and remove the service named pipe
if (srv_close (&srv) < 0) { if (server_close (&srv) < 0) {
handle_error("srv_close < 0"); handle_error("server_close < 0");
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -29,18 +29,18 @@ void pubsub_quit (struct service *srv)
// line fmt : 0 0 0 quit // line fmt : 0 0 0 quit
char line[BUFSIZ]; char line[BUFSIZ];
snprintf (line, BUFSIZ, "0 0 0 quit\n"); snprintf (line, BUFSIZ, "0 0 0 quit\n");
app_srv_connection (srv, line, strlen (line)); application_server_connection (srv, line, strlen (line));
} }
#endif #endif
int pubsub_connection (int argc, char **argv, char **env int pubsub_connection (int argc, char **argv, char **env
, struct service *srv) , struct service *srv)
{ {
int ret = app_connection (argc, argv, env int ret = application_connection (argc, argv, env
, srv, PUBSUBD_SERVICE_NAME, NULL, 0); , srv, PUBSUBD_SERVICE_NAME, NULL, 0);
if (ret != 0) { if (ret != 0) {
handle_err ("pubsub_connection", "app_connection != 0"); handle_err ("pubsub_connection", "application_connection != 0");
} }
return ret; return ret;
@ -48,7 +48,7 @@ int pubsub_connection (int argc, char **argv, char **env
int pubsub_disconnect (struct service *srv) int pubsub_disconnect (struct service *srv)
{ {
return app_close (srv); return application_close (srv);
} }
int pubsub_msg_send (struct service *srv, const struct pubsub_msg * m) int pubsub_msg_send (struct service *srv, const struct pubsub_msg * m)
@ -68,7 +68,7 @@ int pubsub_msg_send (struct service *srv, const struct pubsub_msg * m)
return -1; return -1;
} }
app_write (srv, &m_data); application_write (srv, &m_data);
msg_free (&m_data); msg_free (&m_data);
if (buf != NULL) if (buf != NULL)
@ -92,7 +92,7 @@ int pubsub_msg_recv (struct service *srv, struct pubsub_msg *m)
struct msg m_recv; struct msg m_recv;
memset (&m_recv, 0, sizeof (struct msg)); memset (&m_recv, 0, sizeof (struct msg));
app_read (srv, &m_recv); application_read (srv, &m_recv);
pubsub_msg_unserialize (m, m_recv.val, m_recv.valsize); pubsub_msg_unserialize (m, m_recv.val, m_recv.valsize);
msg_free (&m_recv); msg_free (&m_recv);

View File

@ -33,7 +33,7 @@ void pubsubd_send (const struct array_proc *ap, const struct pubsub_msg * m)
int i; int i;
for (i = 0; i < ap->size ; i++) { for (i = 0; i < ap->size ; i++) {
srv_write (ap->tab_proc[i], &m_data); server_write (ap->tab_proc[i], &m_data);
} }
msg_free (&m_data); msg_free (&m_data);
@ -48,7 +48,7 @@ void pubsubd_send (const struct array_proc *ap, const struct pubsub_msg * m)
// memset (&m_data, 0, sizeof (struct msg)); // memset (&m_data, 0, sizeof (struct msg));
// //
// // read the message from the process // // read the message from the process
// srv_read (p, &m_data); // server_read (p, &m_data);
// //
// pubsub_msg_unserialize (m, m_data.val, m_data.valsize); // pubsub_msg_unserialize (m, m_data.val, m_data.valsize);
// //
@ -64,8 +64,8 @@ void handle_new_connection (struct service *srv, struct array_proc *ap)
struct process *p = malloc(sizeof(struct process)); struct process *p = malloc(sizeof(struct process));
memset(p, 0, sizeof(struct process)); memset(p, 0, sizeof(struct process));
if (srv_accept (srv, p) < 0) { if (server_accept (srv, p) < 0) {
handle_error("srv_accept < 0"); handle_error("server_accept < 0");
} else { } else {
printf("new connection\n"); printf("new connection\n");
} }
@ -83,8 +83,8 @@ 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 (srv_read (proc_to_read->tab_proc[i], &m) < 0) { if (server_read (proc_to_read->tab_proc[i], &m) < 0) {
handle_error("srv_read < 0"); handle_error("server_read < 0");
} }
mprint_hexa ("msg received: ", (unsigned char *) m.val, m.valsize); mprint_hexa ("msg received: ", (unsigned char *) m.val, m.valsize);
@ -99,8 +99,8 @@ void handle_new_msg (struct channels *chans
pubsubd_channels_unsubscribe_everywhere (chans, p); pubsubd_channels_unsubscribe_everywhere (chans, p);
// close the connection to the process // close the connection to the process
if (srv_close_proc (p) < 0) if (server_close_proc (p) < 0)
handle_error( "srv_close_proc < 0"); handle_error( "server_close_proc < 0");
// remove the process from the processes list // remove the process from the processes list
@ -176,7 +176,7 @@ void pubsubd_main_loop (struct service *srv, struct channels *chans)
memset(&proc_to_read, 0, sizeof(struct array_proc)); memset(&proc_to_read, 0, sizeof(struct array_proc));
while(1) { while(1) {
ret = srv_select (&ap, srv, &proc_to_read); ret = server_select (&ap, srv, &proc_to_read);
if (ret == CONNECTION) { if (ret == CONNECTION) {
handle_new_connection (srv, &ap); handle_new_connection (srv, &ap);
@ -190,8 +190,8 @@ void pubsubd_main_loop (struct service *srv, struct channels *chans)
} }
for (i = 0; i < ap.size; i++) { for (i = 0; i < ap.size; i++) {
if (srv_close_proc (ap.tab_proc[i]) < 0) { if (server_close_proc (ap.tab_proc[i]) < 0) {
handle_error( "srv_close_proc < 0"); handle_error( "server_close_proc < 0");
} }
} }

View File

@ -26,15 +26,15 @@ void sim_connection (int argc, char **argv, char **env, pid_t pid, int index, in
struct service srv; struct service srv;
memset (&srv, 0, sizeof (struct service)); memset (&srv, 0, sizeof (struct service));
srv_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL); server_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
printf ("Writing on %s.\n", srv.spath); printf ("Writing on %s.\n", srv.spath);
struct process p; struct process p;
memset (&p, 0, sizeof (struct process)); memset (&p, 0, sizeof (struct process));
printf ("app creation\n"); printf ("app creation\n");
if (app_create (&p, pid, index, version)) // called by the application if (application_create (&p, pid, index, version)) // called by the application
ohshit (1, "app_create"); ohshit (1, "application_create");
printf ("connection\n"); printf ("connection\n");
// send a message to warn the service we want to do something // send a message to warn the service we want to do something
@ -74,22 +74,22 @@ void sim_connection (int argc, char **argv, char **env, pid_t pid, int index, in
printf ("destroying app\n"); printf ("destroying app\n");
// the application will shut down, and remove the application named pipes // the application will shut down, and remove the application named pipes
if (app_destroy (&p)) if (application_destroy (&p))
ohshit (1, "app_destroy"); ohshit (1, "application_destroy");
} }
void sim_disconnection (int argc, char **argv, char **env, pid_t pid, int index, int version) void sim_disconnection (int argc, char **argv, char **env, pid_t pid, int index, int version)
{ {
struct service srv; struct service srv;
memset (&srv, 0, sizeof (struct service)); memset (&srv, 0, sizeof (struct service));
srv_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL); server_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
printf ("Disconnecting from %s.\n", srv.spath); printf ("Disconnecting from %s.\n", srv.spath);
struct process p; struct process p;
memset (&p, 0, sizeof (struct process)); memset (&p, 0, sizeof (struct process));
// create the fake process // create the fake process
srv_process_gen (&p, pid, index, version); server_process_gen (&p, pid, index, version);
// send a message to disconnect // send a message to disconnect
// line : pid index version action chan // line : pid index version action chan

View File

@ -19,7 +19,7 @@ main(int argc, char **argv, char **env)
{ {
struct service srv; struct service srv;
memset (&srv, 0, sizeof (struct service)); memset (&srv, 0, sizeof (struct service));
srv_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL); server_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
printf ("Writing on %s.\n", srv.spath); printf ("Writing on %s.\n", srv.spath);
struct process p; struct process p;
@ -28,8 +28,8 @@ main(int argc, char **argv, char **env)
pid_t pid = getpid(); pid_t pid = getpid();
if (app_create (&p, pid, index, COMMUNICATION_VERSION)) if (application_create (&p, pid, index, COMMUNICATION_VERSION))
ohshit (1, "app_create"); ohshit (1, "application_create");
// send a message to warn the service we want to do something // send a message to warn the service we want to do something
// line : pid index version action chan // line : pid index version action chan
@ -55,8 +55,8 @@ main(int argc, char **argv, char **env)
pubsubd_msg_free (&m); pubsubd_msg_free (&m);
// the application will shut down, and remove the application named pipes // the application will shut down, and remove the application named pipes
if (app_destroy (&p)) if (application_destroy (&p))
ohshit (1, "app_destroy"); ohshit (1, "application_destroy");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -19,8 +19,8 @@ struct service srv;
void handle_signal (int signalnumber) void handle_signal (int signalnumber)
{ {
// the application will shut down, and remove the service unix socket // the application will shut down, and remove the service unix socket
if (srv_close (&srv) < 0) { if (server_close (&srv) < 0) {
handle_error("srv_close < 0"); handle_error("server_close < 0");
} }
log_info ("remoted received a signal %d\n", signalnumber); log_info ("remoted received a signal %d\n", signalnumber);
@ -95,8 +95,8 @@ int main(int argc, char **argv, char **env)
else else
log_info ("remoted configuration loaded"); log_info ("remoted configuration loaded");
if (srv_init (argc, argv, env, &srv, REMOTED_SERVICE_NAME) < 0) { if (server_init (argc, argv, env, &srv, REMOTED_SERVICE_NAME) < 0) {
handle_error("srv_init < 0"); handle_error("server_init < 0");
} }
log_info ("remoted listening on %s", srv.spath); log_info ("remoted listening on %s", srv.spath);
@ -106,8 +106,8 @@ int main(int argc, char **argv, char **env)
remoted_main_loop (&srv, &ctx); remoted_main_loop (&srv, &ctx);
// the application will shut down, and remove the service unix socket // the application will shut down, and remove the service unix socket
if (srv_close (&srv) < 0) { if (server_close (&srv) < 0) {
handle_error("srv_close < 0"); handle_error("server_close < 0");
} }
log_info ("remoted ended"); log_info ("remoted ended");

View File

@ -9,11 +9,11 @@
int remotec_connection (int argc, char **argv, char **env, struct service *srv) int remotec_connection (int argc, char **argv, char **env, struct service *srv)
{ {
int ret = app_connection (argc, argv, env int ret = application_connection (argc, argv, env
, srv, REMOTED_SERVICE_NAME, NULL, 0); , srv, REMOTED_SERVICE_NAME, NULL, 0);
if (ret != 0) { if (ret != 0) {
handle_err ("remote remotec_connection", "app_connection != 0"); handle_err ("remote remotec_connection", "application_connection != 0");
} }
return ret; return ret;
@ -21,7 +21,7 @@ int remotec_connection (int argc, char **argv, char **env, struct service *srv)
int remotec_disconnection (struct service *srv) int remotec_disconnection (struct service *srv)
{ {
return app_close (srv); return application_close (srv);
} }
int remotec_msg_send (struct service *srv, const struct remoted_msg * m) int remotec_msg_send (struct service *srv, const struct remoted_msg * m)
@ -41,7 +41,7 @@ int remotec_msg_send (struct service *srv, const struct remoted_msg * m)
return -1; return -1;
} }
app_write (srv, &m_data); application_write (srv, &m_data);
msg_free (&m_data); msg_free (&m_data);
if (buf != NULL) if (buf != NULL)
@ -65,7 +65,7 @@ int remotec_msg_recv (struct service *srv, struct remoted_msg *m)
struct msg m_recv; struct msg m_recv;
memset (&m_recv, 0, sizeof (struct msg)); memset (&m_recv, 0, sizeof (struct msg));
app_read (srv, &m_recv); application_read (srv, &m_recv);
remote_msg_unserialize (m, m_recv.val, m_recv.valsize); remote_msg_unserialize (m, m_recv.val, m_recv.valsize);
msg_free (&m_recv); msg_free (&m_recv);

View File

@ -20,8 +20,8 @@ void handle_new_connection (struct service *srv, struct array_proc *ap)
struct process *p = malloc(sizeof(struct process)); struct process *p = malloc(sizeof(struct process));
memset(p, 0, sizeof(struct process)); memset(p, 0, sizeof(struct process));
if (srv_accept (srv, p) < 0) { if (server_accept (srv, p) < 0) {
handle_error("srv_accept < 0"); handle_error("server_accept < 0");
} else { } else {
log_debug ("remoted, new connection", p->proc_fd); log_debug ("remoted, new connection", p->proc_fd);
} }
@ -37,8 +37,8 @@ void handle_new_msg (struct array_proc *ap, struct array_proc *proc_to_read)
memset (&m, 0, sizeof (struct msg)); memset (&m, 0, sizeof (struct msg));
int i; int i;
for (i = 0; i < proc_to_read->size; i++) { for (i = 0; i < proc_to_read->size; i++) {
if (srv_read (proc_to_read->tab_proc[i], &m) < 0) { if (server_read (proc_to_read->tab_proc[i], &m) < 0) {
handle_error("srv_read < 0"); handle_error("server_read < 0");
} }
mprint_hexa ("msg received: ", (unsigned char *) m.val, m.valsize); mprint_hexa ("msg received: ", (unsigned char *) m.val, m.valsize);
@ -50,8 +50,8 @@ void handle_new_msg (struct array_proc *ap, struct array_proc *proc_to_read)
log_debug ("remoted, proc %d disconnecting", p->proc_fd); log_debug ("remoted, proc %d disconnecting", p->proc_fd);
// close the connection to the process // close the connection to the process
if (srv_close_proc (p) < 0) if (server_close_proc (p) < 0)
handle_error( "srv_close_proc < 0"); handle_error( "server_close_proc < 0");
// remove the process from the processes list // remove the process from the processes list
if (del_proc (ap, p) < 0) if (del_proc (ap, p) < 0)
@ -122,7 +122,7 @@ void remoted_main_loop (struct service *srv, struct remoted_ctx *ctx)
while(1) { while(1) {
/* TODO: authorizations */ /* TODO: authorizations */
ret = srv_select (&ap, srv, &proc_to_read); ret = server_select (&ap, srv, &proc_to_read);
if (ret == CONNECTION) { if (ret == CONNECTION) {
handle_new_connection (srv, &ap); handle_new_connection (srv, &ap);
@ -136,8 +136,8 @@ void remoted_main_loop (struct service *srv, struct remoted_ctx *ctx)
} }
for (i = 0; i < ap.size; i++) { for (i = 0; i < ap.size; i++) {
if (srv_close_proc (ap.tab_proc[i]) < 0) { if (server_close_proc (ap.tab_proc[i]) < 0) {
handle_error( "srv_close_proc < 0"); handle_error( "server_close_proc < 0");
} }
} }
} }

View File

@ -15,7 +15,6 @@
#include <linux/limits.h> #include <linux/limits.h>
#define PORT 6000 #define PORT 6000
#define TMPDIR "/tmp/ipc/"
#define NBCLIENT 10 #define NBCLIENT 10
#define SERVICE_TCP "tcpd" #define SERVICE_TCP "tcpd"
#define LISTEN_BACKLOG 50 #define LISTEN_BACKLOG 50
@ -127,15 +126,15 @@ void * service_thread(void * c_data) {
memset (&srv, 0, sizeof (struct service)); memset (&srv, 0, sizeof (struct service));
srv->index = 0; srv->index = 0;
srv->version = 0; srv->version = 0;
srv_init (0, NULL, NULL, &srv, service, NULL); server_init (0, NULL, NULL, &srv, service, NULL);
if (app_srv_connection(&srv, piv, strlen(piv)) == -1) { if (application_server_connection(&srv, piv, strlen(piv)) == -1) {
handle_error("app_srv_connection\n"); handle_error("application_server_connection\n");
} }
free(piv); free(piv);
/*struct process p; /*struct process p;
app_create(&p, getpid(), cda->index, version); application_create(&p, getpid(), cda->index, version);
srv_process_print(&p);*/ server_process_print(&p);*/
//sleep(1); //sleep(1);
//printf("%s\n",p.path_proc ); //printf("%s\n",p.path_proc );
/*if (proc_connection(&p) == -1){ /*if (proc_connection(&p) == -1){
@ -165,7 +164,7 @@ void * service_thread(void * c_data) {
if (FD_ISSET(srv.service_fd, &rdfs)){ if (FD_ISSET(srv.service_fd, &rdfs)){
nbytes = file_read(srv.service_fd, &buffer); nbytes = file_read(srv.service_fd, &buffer);
if(nbytes < 0) { if(nbytes < 0) {
perror("app_read()"); perror("application_read()");
} }
printf("message from file : %s\n", buffer ); printf("message from file : %s\n", buffer );
write_message(clientSock, buffer, nbytes); write_message(clientSock, buffer, nbytes);
@ -357,7 +356,7 @@ void * server_thread(void * reqq) {
* listen = server for a service such as pongd * listen = server for a service such as pongd
* connect = connect to a server * connect = connect to a server
*/ */
int srv_get_new_request(char *buf, info_request *req) { int server_get_new_request(char *buf, info_request *req) {
char *token = NULL, *saveptr = NULL; char *token = NULL, *saveptr = NULL;
char *str = NULL; char *str = NULL;
@ -402,7 +401,7 @@ int srv_get_new_request(char *buf, info_request *req) {
req->addr.sin_family = AF_INET; req->addr.sin_family = AF_INET;
if (strcmp("connect", req->request) == 0) { if (strcmp("connect", req->request) == 0) {
srv_process_gen (req->p, pid, index, version); server_process_gen (req->p, pid, index, version);
} }
return 1; return 1;
@ -515,7 +514,7 @@ void * client_thread(void *reqq) {
int n = read_message(sock, buffer); int n = read_message(sock, buffer);
if(n > 0) { if(n > 0) {
printf("Client : message from server(%d bytes) : %s\n", n, buffer); printf("Client : message from server(%d bytes) : %s\n", n, buffer);
if(app_write(req->p, buffer, strlen(buffer)) < 0) { if(application_write(req->p, buffer, strlen(buffer)) < 0) {
perror("file_write"); perror("file_write");
} }
nbMessages--; nbMessages--;
@ -528,7 +527,7 @@ void * client_thread(void *reqq) {
break; break;
} }
}else { }else {
nbytes = app_read (req->p, &buffer); nbytes = application_read (req->p, &buffer);
printf("Client : message from app %d : %s\n",nbytes, buffer ); printf("Client : message from app %d : %s\n",nbytes, buffer );
if ( nbytes == -1) { if ( nbytes == -1) {
handle_error("file_read"); handle_error("file_read");
@ -666,10 +665,10 @@ void main_loop (struct service *srv) {
tab_req[nbclient].p = malloc(sizeof(struct process)); tab_req[nbclient].p = malloc(sizeof(struct process));
// -1 : error, 0 = no new process, 1 = new process // -1 : error, 0 = no new process, 1 = new process
ret = srv_get_new_request (buf, &tab_req[nbclient]); ret = server_get_new_request (buf, &tab_req[nbclient]);
tab_req[nbclient].p->proc_fd = newfd; tab_req[nbclient].p->proc_fd = newfd;
if (ret == -1) { if (ret == -1) {
perror("srv_get_new_request()"); perror("server_get_new_request()");
exit(1); exit(1);
} else if (ret == 0) { } else if (ret == 0) {
break; break;
@ -717,10 +716,10 @@ void main_loop (struct service *srv) {
tab_req[nbclient].p = malloc(sizeof(struct process)); tab_req[nbclient].p = malloc(sizeof(struct process));
// -1 : error, 0 = no new process, 1 = new process // -1 : error, 0 = no new process, 1 = new process
ret = srv_get_new_request (buf, &tab_req[nbclient]); ret = server_get_new_request (buf, &tab_req[nbclient]);
tab_req[nbclient].p->proc_fd = i; tab_req[nbclient].p->proc_fd = i;
if (ret == -1) { if (ret == -1) {
perror("srv_get_new_request()"); perror("server_get_new_request()");
exit(1); exit(1);
} else if (ret == 0) { } else if (ret == 0) {
break; break;
@ -776,12 +775,12 @@ void main_loop (struct service *srv) {
int main(int argc, char * argv[], char **env) { int main(int argc, char * argv[], char **env) {
struct service srv; struct service srv;
srv_init (argc, argv, env, &srv, SERVICE_TCP, NULL); server_init (argc, argv, env, &srv, SERVICE_TCP, NULL);
printf ("Listening on %s.\n", srv.spath); printf ("Listening on %s.\n", srv.spath);
// creates the service named pipe, that listens to client applications // creates the service named pipe, that listens to client applications
int ret; int ret;
if ((ret = srv_create (&srv))) { if ((ret = server_create (&srv))) {
fprintf(stdout, "error service_create %d\n", ret); fprintf(stdout, "error service_create %d\n", ret);
exit (1); exit (1);
} }
@ -791,7 +790,7 @@ int main(int argc, char * argv[], char **env) {
main_loop (&srv); main_loop (&srv);
// the application will shut down, and remove the service named pipe // the application will shut down, and remove the service named pipe
if ((ret = srv_close (&srv))) { if ((ret = server_close (&srv))) {
fprintf(stdout, "error service_close %d\n", ret); fprintf(stdout, "error service_close %d\n", ret);
exit (1); exit (1);
} }

View File

@ -48,7 +48,7 @@ void * server_thread(void *reqq);
void * client_thread(void *reqq); void * client_thread(void *reqq);
int srv_get_new_request(char *buf, info_request *req); int server_get_new_request(char *buf, info_request *req);
void request_print (const info_request *req); void request_print (const info_request *req);

View File

@ -9,11 +9,11 @@
do { perror(msg); exit(EXIT_FAILURE); } while (0) do { perror(msg); exit(EXIT_FAILURE); } while (0)
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
char *srv_message = malloc(BUFSIZ); char *server_message = malloc(BUFSIZ);
char *pidfile = malloc(BUFSIZ); char *pidfile = malloc(BUFSIZ);
char *buffer = malloc(BUFSIZ); char *buffer = malloc(BUFSIZ);
snprintf(srv_message, BUFSIZ, "%s %d 1 1", "connect 127.0.0.1 6000", getpid()); snprintf(server_message, BUFSIZ, "%s %d 1 1", "connect 127.0.0.1 6000", getpid());
snprintf(pidfile, BUFSIZ, "%s%d-1-1", "/tmp/ipc/", getpid()); snprintf(pidfile, BUFSIZ, "%s%d-1-1", "/tmp/ipc/", getpid());
char *proc_message = "hello frero"; char *proc_message = "hello frero";
@ -38,7 +38,7 @@ int main(int argc, char * argv[]) {
exit(errno); exit(errno);
} }
//printf("connected...\n"); //printf("connected...\n");
file_write(sfd, srv_message, strlen(srv_message)); file_write(sfd, server_message, strlen(server_message));
//printf("%s\n", proc_message); //printf("%s\n", proc_message);
//sleep(1); //sleep(1);
file_write(sfd, proc_message, strlen(proc_message)); file_write(sfd, proc_message, strlen(proc_message));