From 3eeb96b21dfdff097adb0a01dbdb39b9848ce172 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Wed, 3 Oct 2018 21:24:20 +0200 Subject: [PATCH] cleaning names --- core-test/app/communication-client.c | 16 ++++----- core-test/app/communication-server.c | 28 +++++++-------- core/communication.c | 44 +++++++++++------------ core/communication.h | 28 +++++++-------- core/process.c | 6 ++-- core/process.h | 6 ++-- drop/init-connection.c | 16 ++++----- man/communication.h.3 | 48 +++++++++++++------------- pong/app/pong.c | 32 ++++++++--------- pong/app/pongd.c | 30 ++++++++-------- pubsub/app/pubsubd.c | 12 +++---- pubsub/lib/pubsub.c | 12 +++---- pubsub/lib/pubsubd.c | 22 ++++++------ pubsub/tests/pubsub-test-send-params.c | 14 ++++---- pubsub/tests/pubsub-test-send.c | 10 +++--- remote/app/remoted.c | 12 +++---- remote/lib/remotec.c | 10 +++--- remote/lib/remoted.c | 18 +++++----- tcp/app/tcpd.c | 35 +++++++++---------- tcp/app/tcpd.h | 2 +- tcp/test/tcpdtest.c | 6 ++-- 21 files changed, 203 insertions(+), 204 deletions(-) diff --git a/core-test/app/communication-client.c b/core-test/app/communication-client.c index 348a321..5231e2d 100644 --- a/core-test/app/communication-client.c +++ b/core-test/app/communication-client.c @@ -22,8 +22,8 @@ int main (int argc, char *argv[], char *env[]) srv.version = 0; // init service - if (app_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) { - handle_err("main", "srv_init < 0"); + if (application_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) { + handle_err("main", "server_init < 0"); return EXIT_FAILURE; } @@ -31,22 +31,22 @@ int main (int argc, char *argv[], char *env[]) msg_format_data (&m, MSG, strlen(MSG) +1); printf ("msg to send in the client: "); print_msg (&m); - if (app_write (&srv, &m) < 0) { - handle_err("main", "app_write < 0"); + if (application_write (&srv, &m) < 0) { + handle_err("main", "application_write < 0"); return EXIT_FAILURE; } msg_free (&m); - if (app_read (&srv, &m) < 0) { - handle_err("main", "app_read < 0"); + if (application_read (&srv, &m) < 0) { + handle_err("main", "application_read < 0"); return EXIT_FAILURE; } printf ("msg recv: %s\n", m.val); msg_free (&m); - if (app_close (&srv) < 0) { - handle_err("main", "app_close < 0"); + if (application_close (&srv) < 0) { + handle_err("main", "application_close < 0"); return EXIT_FAILURE; } diff --git a/core-test/app/communication-server.c b/core-test/app/communication-server.c index d29d40a..49267fb 100644 --- a/core-test/app/communication-server.c +++ b/core-test/app/communication-server.c @@ -24,32 +24,32 @@ int main (int argc, char *argv[], char *env[]) memset (&p, 0, sizeof (struct process)); // init service - if (srv_init (argc, argv, env, &srv, SERVICE_NAME) < 0) { - handle_err("main", "srv_init < 0"); + if (server_init (argc, argv, env, &srv, SERVICE_NAME) < 0) { + handle_err("main", "server_init < 0"); return EXIT_FAILURE; } - if (srv_accept (&srv, &p) < 0) { - handle_err("main", "srv_accept < 0"); + if (server_accept (&srv, &p) < 0) { + handle_err("main", "server_accept < 0"); return EXIT_FAILURE; } - if (srv_read (&p, &m) < 0) { - handle_err("main", "srv_read < 0"); + if (server_read (&p, &m) < 0) { + handle_err("main", "server_read < 0"); return EXIT_FAILURE; } printf ("msg recv: %s\n", m.val); - if (srv_write (&p, &m) < 0) { - handle_err("main", "srv_write < 0"); + if (server_write (&p, &m) < 0) { + handle_err("main", "server_write < 0"); return EXIT_FAILURE; } msg_free (&m); // client quits - if (srv_read (&p, &m) < 0) { - handle_err("main", "srv_read < 0"); + if (server_read (&p, &m) < 0) { + handle_err("main", "server_read < 0"); return EXIT_FAILURE; } if (m.type == MSG_TYPE_CLOSE) { @@ -60,13 +60,13 @@ int main (int argc, char *argv[], char *env[]) } msg_free (&m); - if (srv_close_proc (&p) < 0) { - handle_err("main", "srv_close_proc < 0"); + if (server_close_proc (&p) < 0) { + handle_err("main", "server_close_proc < 0"); return EXIT_FAILURE; } - if (srv_close (&srv) < 0) { - handle_err("main", "srv_close < 0"); + if (server_close (&srv) < 0) { + handle_err("main", "server_close < 0"); return EXIT_FAILURE; } diff --git a/core/communication.c b/core/communication.c index 491012e..6efcb4a 100644 --- a/core/communication.c +++ b/core/communication.c @@ -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); } -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) { if (srv == NULL) @@ -37,7 +37,7 @@ int srv_init (int argc, char **argv, char **env 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 (p != NULL); @@ -46,49 +46,49 @@ int srv_accept (struct service *srv, struct process *p) struct msg m_con; 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 msg_free (&m_con); struct msg m_ack; memset (&m_ack, 0, sizeof (struct msg)); msg_format_ack (&m_ack, NULL, 0); - srv_write (p, &m_ack); + ipc_server_write (p, &m_ack); msg_free (&m_ack); return 0; } -int srv_close (struct service *srv) +int ipc_server_close (struct service *srv) { usock_close (srv->service_fd); 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; // memset (&m_ack_dis, 0, sizeof (struct msg)); // m_ack_dis.type = MSG_TYPE_CLOSE; // 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); } -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); } -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); } -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 , const char *connectionstr, size_t msize) { @@ -114,18 +114,18 @@ int app_connection (int argc, char **argv, char **env // format the connection msg 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; } // send connection msg - app_write (srv, &m_con); + ipc_application_write (srv, &m_con); msg_free (&m_con); // receive ack msg struct msg m_ack; 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.valsize == 0); @@ -135,24 +135,24 @@ int app_connection (int argc, char **argv, char **env } // send a CLOSE message then close the socket -int app_close (struct service *srv) +int ipc_application_close (struct service *srv) { struct msg m; memset (&m, 0, sizeof (struct msg)); m.type = MSG_TYPE_CLOSE; 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); } -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); } -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); } @@ -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 * * le service qui attend de nouvelles connexions * * un tableau de process qui souhaitent parler @@ -187,7 +187,7 @@ int getMaxFd(struct array_proc *ap) * * 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) { assert (ap != NULL); @@ -222,7 +222,7 @@ int srv_select (struct array_proc *ap, struct service *srv int is_listener = 0; do { - // printf ("loop srv_select main_loop\n"); + // printf ("loop ipc_server_select main_loop\n"); readf = master; if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) { 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*/ 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 (i == listener) { is_listener = 1; } else { 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 ) { add_proc (proc, ap->tab_proc[j]); } diff --git a/core/communication.h b/core/communication.h index d9e9128..ab8e4e1 100644 --- a/core/communication.h +++ b/core/communication.h @@ -14,7 +14,7 @@ #define ER_MEM_ALLOC 100 #define ER_PARAMS 101 -#define TMPDIR "/tmp/ipc/" +#define TMPDIR "/run/ipc/" #define PATH_MAX BUFSIZ @@ -34,28 +34,28 @@ struct service { // srv->version and srv->index must be already set // init unix socket + fill srv->spath -int srv_init (int argc, char **argv, char **env - , struct service *srv, const char *sname); -int srv_close (struct service *srv); -int srv_close_proc (struct process *p); -int srv_accept (struct service *srv, struct process *p); +int ipc_server_init (int argc, char **argv, char **env + , struct service *srv, const char *sname); +int ipc_server_close (struct service *srv); +int ipc_server_close_proc (struct process *p); +int ipc_server_accept (struct service *srv, struct process *p); -int srv_read (const struct process *, struct msg *m); -int srv_write (const struct process *, const struct msg *m); +int ipc_server_read (const struct process *, 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 // Initialize connection with unix socket // send the connection string to $TMP/ // fill srv->spath && srv->service_fd -int app_connection (int argc, char **argv, char **env - , struct service *, const char *, const char *, size_t); -int app_close (struct service *); +int ipc_application_connection (int argc, char **argv, char **env + , struct service *, const char *, const char *, size_t); +int ipc_application_close (struct service *); -int app_read (struct service *srv, struct msg *m); -int app_write (struct service *, const struct msg *m); +int ipc_application_read (struct service *srv, struct msg *m); +int ipc_application_write (struct service *, const struct msg *m); diff --git a/core/process.c b/core/process.c index c8b2e54..0d760e3 100644 --- a/core/process.c +++ b/core/process.c @@ -5,7 +5,7 @@ #include -struct process * srv_process_copy (const struct process *p) +struct process * server_process_copy (const struct process *p) { if (p == NULL) return NULL; @@ -16,13 +16,13 @@ struct process * srv_process_copy (const struct process *p) 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 && 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) { p->version = version; diff --git a/core/process.h b/core/process.h index 5493941..28df707 100644 --- a/core/process.h +++ b/core/process.h @@ -18,10 +18,10 @@ int del_proc (struct array_proc *aproc, struct process *p); void array_proc_print (struct array_proc *); void array_proc_free (struct array_proc *); -struct process * srv_process_copy (const struct process *p); -int srv_process_eq (const struct process *p1, const struct process *p2); +struct process * server_process_copy (const struct process *p); +int server_process_eq (const struct process *p1, const struct process *p2); // 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); void process_print (struct process *); diff --git a/drop/init-connection.c b/drop/init-connection.c index 143712a..2413fa4 100644 --- a/drop/init-connection.c +++ b/drop/init-connection.c @@ -12,11 +12,11 @@ int main(int argc, char * argv[], char *env[]) { struct service srv; 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); // creates the service named pipe, that listens to client applications - if (srv_create (&srv)) + if (server_create (&srv)) ohshit(1, "service_create error"); /* @@ -30,8 +30,8 @@ int main(int argc, char * argv[], char *env[]) int version = 1; printf ("app creation\n"); - if (app_create (&p, index, version)) // called by the application - ohshit (1, "app_create"); + if (application_create (&p, index, version)) // called by the application + ohshit (1, "application_create"); /* * some exchanges between App and S @@ -41,16 +41,16 @@ int main(int argc, char * argv[], char *env[]) printf ("destroying app\n"); // the application will shut down, and remove the application named pipes - if (app_destroy (&p)) - ohshit (1, "app_destroy"); + if (application_destroy (&p)) + ohshit (1, "application_destroy"); /* * /PROCESS */ // the application will shut down, and remove the service named pipe - if (srv_close (&srv)) - ohshit (1, "srv_close error"); + if (server_close (&srv)) + ohshit (1, "server_close error"); return EXIT_SUCCESS; } diff --git a/man/communication.h.3 b/man/communication.h.3 index fcf2b31..86d2284 100644 --- a/man/communication.h.3 +++ b/man/communication.h.3 @@ -5,31 +5,31 @@ communication.h \- all functions explained .nf .B #include .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 "int srv_accept (struct service *" srv ", struct process *" p ); +.BI "int server_accept (struct service *" srv ", struct process *" p ); .sp -.BI "int srv_read (const struct process *" p ", struct msg *" message ); -.BI "int srv_write (const struct process *" p ", const struct msg *" message ); +.BI "int server_read (const struct process *" p ", struct msg *" message ); +.BI "int server_write (const struct process *" p ", const struct msg *" message ); .sp -.BI "int srv_close (struct service *" srv ); -.BI "int srv_close_proc (struct process *" p ); -.BI "int srv_select (struct array_proc *" fds ", struct service *" srv ", struct array_proc *" readfds ); +.BI "int server_close (struct service *" srv ); +.BI "int server_close_proc (struct process *" p ); +.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 *" connection_buffer ", size_t " bufsize ); .sp -.BI "int app_read (const struct service *" srv ", struct msg *" message ); -.BI "int app_write (const struct service *" srv ", const struct msg *" message ); +.BI "int application_read (const struct service *" srv ", struct msg *" message ); +.BI "int application_write (const struct service *" srv ", const struct msg *" message ); .sp -.BI "int app_close (struct service *" srv ); +.BI "int application_close (struct service *" srv ); .fi .SH DESCRIPTION The -.BR srv_init () +.BR server_init () function let the service declare itself, create a new unix socket and listen. .I argc , @@ -40,28 +40,28 @@ should be passed to the function in order to automatically change the behavior o .I *srv 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 The -.BR srv_accept () +.BR server_accept () function accepts new connections. .IR p parameter is the client process that will be provided after the connection. .PP The -.BR srv_read () +.BR server_read () and -.BR srv_write () +.BR server_write () functions take respectively a message to read from, and a message to write to a process. .PP The -.BR srv_close_proc () +.BR server_close_proc () 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). .PP The -.BR srv_select () +.BR server_select () takes three arguments, .IR *ap 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. .PP The -.BR app_connection () +.BR application_connection () function takes .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. .PP The -.BR app_read () +.BR application_read () and -.BR app_write () +.BR application_write () functions take respectively a message to read from, and a message to write to the service. .PP The -.BR app_close () +.BR application_close () function finally ends the communication to the service. .SH RETURN VALUE Most of the functions return an integer less than zero if there is an error. .PP 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. diff --git a/pong/app/pong.c b/pong/app/pong.c index 966c91c..fdc2bfa 100644 --- a/pong/app/pong.c +++ b/pong/app/pong.c @@ -22,8 +22,8 @@ void non_interactive (int argc, char *argv[], char *env[]) srv.version = 0; // init service - if (app_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) { - handle_err("main", "srv_init < 0"); + if (ipc_application_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) { + handle_err("main", "server_init < 0"); exit (EXIT_FAILURE); } @@ -31,22 +31,22 @@ void non_interactive (int argc, char *argv[], char *env[]) msg_format_data (&m, MSG, strlen(MSG) +1); printf ("msg to send in the client: "); print_msg (&m); - if (app_write (&srv, &m) < 0) { - handle_err("main", "app_write < 0"); + if (ipc_application_write (&srv, &m) < 0) { + handle_err("main", "application_write < 0"); exit (EXIT_FAILURE); } msg_free (&m); - if (app_read (&srv, &m) < 0) { - handle_err("main", "app_read < 0"); + if (ipc_application_read (&srv, &m) < 0) { + handle_err("main", "application_read < 0"); exit (EXIT_FAILURE); } printf ("msg recv: %s\n", m.val); msg_free (&m); - if (app_close (&srv) < 0) { - handle_err("main", "app_close < 0"); + if (ipc_application_close (&srv) < 0) { + handle_err("main", "application_close < 0"); exit (EXIT_FAILURE); } } @@ -67,8 +67,8 @@ void interactive (int argc, char *argv[], char *env[]) srv.version = 0; // init service - if (app_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) { - handle_err ("main", "srv_init < 0"); + if (ipc_application_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) { + handle_err ("main", "server_init < 0"); exit (EXIT_FAILURE); } @@ -85,14 +85,14 @@ void interactive (int argc, char *argv[], char *env[]) // print_msg (&m); - if (app_write (&srv, &m) < 0) { - handle_err("main", "app_write < 0"); + if (ipc_application_write (&srv, &m) < 0) { + handle_err("main", "application_write < 0"); exit (EXIT_FAILURE); } msg_free (&m); - if (app_read (&srv, &m) < 0) { - handle_err("main", "app_read < 0"); + if (ipc_application_read (&srv, &m) < 0) { + handle_err("main", "application_read < 0"); exit (EXIT_FAILURE); } @@ -100,8 +100,8 @@ void interactive (int argc, char *argv[], char *env[]) msg_free (&m); } - if (app_close (&srv) < 0) { - handle_err("main", "app_close < 0"); + if (ipc_application_close (&srv) < 0) { + handle_err("main", "application_close < 0"); exit (EXIT_FAILURE); } } diff --git a/pong/app/pongd.c b/pong/app/pongd.c index 44715f2..1d4987f 100644 --- a/pong/app/pongd.c +++ b/pong/app/pongd.c @@ -15,8 +15,8 @@ void handle_new_connection (struct service *srv, struct array_proc *ap) struct process *p = malloc(sizeof(struct process)); memset(p, 0, sizeof(struct process)); - if (srv_accept (srv, p) < 0) { - handle_error("srv_accept < 0"); + if (ipc_server_accept (srv, p) < 0) { + handle_error("server_accept < 0"); } else { printf("new connection\n"); } @@ -36,8 +36,8 @@ void handle_new_msg (struct array_proc *ap, struct array_proc *proc_to_read) int i; for (i = 0; i < proc_to_read->size; i++) { // printf ("loop handle_new_msg\n"); - if (srv_read (proc_to_read->tab_proc[i], &m) < 0) { - handle_error("srv_read < 0"); + if (ipc_server_read (proc_to_read->tab_proc[i], &m) < 0) { + handle_error("server_read < 0"); } // 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--; printf ("disconnection => %d client(s) remaining\n", cpt); - if (srv_close_proc (proc_to_read->tab_proc[i]) < 0) - handle_err( "handle_new_msg", "srv_close_proc < 0"); + if (ipc_server_close_proc (proc_to_read->tab_proc[i]) < 0) + handle_err( "handle_new_msg", "server_close_proc < 0"); if (del_proc (ap, proc_to_read->tab_proc[i]) < 0) handle_err( "handle_new_msg", "del_proc < 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); - if (srv_write (proc_to_read->tab_proc[i], &m) < 0) { - handle_err( "handle_new_msg", "srv_write < 0"); + if (ipc_server_write (proc_to_read->tab_proc[i], &m) < 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)); 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"); // array_proc_print (&proc_to_read); // printf ("-- \n\n"); @@ -98,8 +98,8 @@ void main_loop (struct service *srv) } for (i = 0; i < ap.size; i++) { - if (srv_close_proc (ap.tab_proc[i]) < 0) { - handle_error( "srv_close_proc < 0"); + if (ipc_server_close_proc (ap.tab_proc[i]) < 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"); - if (srv_init (argc, argv, env, &srv, PONGD_SERVICE_NAME) < 0) { - handle_error("srv_init < 0"); + if (ipc_server_init (argc, argv, env, &srv, PONGD_SERVICE_NAME) < 0) { + handle_error("server_init < 0"); return EXIT_FAILURE; } printf ("Listening on %s.\n", srv.spath); @@ -136,8 +136,8 @@ int main(int argc, char * argv[], char **env) main_loop (&srv); // the application will shut down, and remove the service named pipe - if (srv_close (&srv) < 0) { - handle_error("srv_close < 0"); + if (ipc_server_close (&srv) < 0) { + handle_error("server_close < 0"); } return EXIT_SUCCESS; diff --git a/pubsub/app/pubsubd.c b/pubsub/app/pubsubd.c index fff1552..c360dae 100644 --- a/pubsub/app/pubsubd.c +++ b/pubsub/app/pubsubd.c @@ -16,8 +16,8 @@ struct channels chans; void handle_signal (int signalnumber) { // the application will shut down, and remove the service named pipe - if (srv_close (&srv) < 0) { - handle_error("srv_close < 0"); + if (server_close (&srv) < 0) { + handle_error("server_close < 0"); } pubsubd_channels_del_all (&chans); @@ -40,8 +40,8 @@ main(int argc, char **argv, char **env) memset (&chans, 0, sizeof (struct channels)); pubsubd_channels_init (&chans); - if (srv_init (argc, argv, env, &srv, PUBSUBD_SERVICE_NAME) < 0) { - handle_error("srv_init < 0"); + if (server_init (argc, argv, env, &srv, PUBSUBD_SERVICE_NAME) < 0) { + handle_error("server_init < 0"); return EXIT_FAILURE; } printf ("Listening on %s.\n", srv.spath); @@ -52,8 +52,8 @@ main(int argc, char **argv, char **env) pubsubd_main_loop (&srv, &chans); // the application will shut down, and remove the service named pipe - if (srv_close (&srv) < 0) { - handle_error("srv_close < 0"); + if (server_close (&srv) < 0) { + handle_error("server_close < 0"); } return EXIT_SUCCESS; diff --git a/pubsub/lib/pubsub.c b/pubsub/lib/pubsub.c index 5858e17..8d52b73 100644 --- a/pubsub/lib/pubsub.c +++ b/pubsub/lib/pubsub.c @@ -29,18 +29,18 @@ void pubsub_quit (struct service *srv) // line fmt : 0 0 0 quit char line[BUFSIZ]; snprintf (line, BUFSIZ, "0 0 0 quit\n"); - app_srv_connection (srv, line, strlen (line)); + application_server_connection (srv, line, strlen (line)); } #endif int pubsub_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, PUBSUBD_SERVICE_NAME, NULL, 0); if (ret != 0) { - handle_err ("pubsub_connection", "app_connection != 0"); + handle_err ("pubsub_connection", "application_connection != 0"); } return ret; @@ -48,7 +48,7 @@ int pubsub_connection (int argc, char **argv, char **env 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) @@ -68,7 +68,7 @@ int pubsub_msg_send (struct service *srv, const struct pubsub_msg * m) return -1; } - app_write (srv, &m_data); + application_write (srv, &m_data); msg_free (&m_data); if (buf != NULL) @@ -92,7 +92,7 @@ int pubsub_msg_recv (struct service *srv, struct pubsub_msg *m) struct msg m_recv; 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); msg_free (&m_recv); diff --git a/pubsub/lib/pubsubd.c b/pubsub/lib/pubsubd.c index 62bfb45..a926fc4 100644 --- a/pubsub/lib/pubsubd.c +++ b/pubsub/lib/pubsubd.c @@ -33,7 +33,7 @@ void pubsubd_send (const struct array_proc *ap, const struct pubsub_msg * m) int 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); @@ -48,7 +48,7 @@ void pubsubd_send (const struct array_proc *ap, const struct pubsub_msg * m) // memset (&m_data, 0, sizeof (struct msg)); // // // 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); // @@ -64,8 +64,8 @@ void handle_new_connection (struct service *srv, struct array_proc *ap) struct process *p = malloc(sizeof(struct process)); memset(p, 0, sizeof(struct process)); - if (srv_accept (srv, p) < 0) { - handle_error("srv_accept < 0"); + if (server_accept (srv, p) < 0) { + handle_error("server_accept < 0"); } else { printf("new connection\n"); } @@ -83,8 +83,8 @@ void handle_new_msg (struct channels *chans int i; for (i = 0; i < proc_to_read->size; i++) { // printf ("loop handle_new_msg\n"); - if (srv_read (proc_to_read->tab_proc[i], &m) < 0) { - handle_error("srv_read < 0"); + if (server_read (proc_to_read->tab_proc[i], &m) < 0) { + handle_error("server_read < 0"); } 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); // close the connection to the process - if (srv_close_proc (p) < 0) - handle_error( "srv_close_proc < 0"); + if (server_close_proc (p) < 0) + handle_error( "server_close_proc < 0"); // 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)); while(1) { - ret = srv_select (&ap, srv, &proc_to_read); + ret = server_select (&ap, srv, &proc_to_read); if (ret == CONNECTION) { 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++) { - if (srv_close_proc (ap.tab_proc[i]) < 0) { - handle_error( "srv_close_proc < 0"); + if (server_close_proc (ap.tab_proc[i]) < 0) { + handle_error( "server_close_proc < 0"); } } diff --git a/pubsub/tests/pubsub-test-send-params.c b/pubsub/tests/pubsub-test-send-params.c index a839d4b..51676cc 100644 --- a/pubsub/tests/pubsub-test-send-params.c +++ b/pubsub/tests/pubsub-test-send-params.c @@ -26,15 +26,15 @@ void sim_connection (int argc, char **argv, char **env, pid_t pid, int index, in struct service srv; 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); struct process p; memset (&p, 0, sizeof (struct process)); printf ("app creation\n"); - if (app_create (&p, pid, index, version)) // called by the application - ohshit (1, "app_create"); + if (application_create (&p, pid, index, version)) // called by the application + ohshit (1, "application_create"); printf ("connection\n"); // 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"); // the application will shut down, and remove the application named pipes - if (app_destroy (&p)) - ohshit (1, "app_destroy"); + if (application_destroy (&p)) + ohshit (1, "application_destroy"); } void sim_disconnection (int argc, char **argv, char **env, pid_t pid, int index, int version) { struct service srv; 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); struct process p; memset (&p, 0, sizeof (struct process)); // create the fake process - srv_process_gen (&p, pid, index, version); + server_process_gen (&p, pid, index, version); // send a message to disconnect // line : pid index version action chan diff --git a/pubsub/tests/pubsub-test-send.c b/pubsub/tests/pubsub-test-send.c index fa3dcc4..9eb107e 100644 --- a/pubsub/tests/pubsub-test-send.c +++ b/pubsub/tests/pubsub-test-send.c @@ -19,7 +19,7 @@ main(int argc, char **argv, char **env) { struct service srv; 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); struct process p; @@ -28,8 +28,8 @@ main(int argc, char **argv, char **env) pid_t pid = getpid(); - if (app_create (&p, pid, index, COMMUNICATION_VERSION)) - ohshit (1, "app_create"); + if (application_create (&p, pid, index, COMMUNICATION_VERSION)) + ohshit (1, "application_create"); // send a message to warn the service we want to do something // line : pid index version action chan @@ -55,8 +55,8 @@ main(int argc, char **argv, char **env) pubsubd_msg_free (&m); // the application will shut down, and remove the application named pipes - if (app_destroy (&p)) - ohshit (1, "app_destroy"); + if (application_destroy (&p)) + ohshit (1, "application_destroy"); return EXIT_SUCCESS; } diff --git a/remote/app/remoted.c b/remote/app/remoted.c index 5d58681..145ca16 100644 --- a/remote/app/remoted.c +++ b/remote/app/remoted.c @@ -19,8 +19,8 @@ struct service srv; void handle_signal (int signalnumber) { // the application will shut down, and remove the service unix socket - if (srv_close (&srv) < 0) { - handle_error("srv_close < 0"); + if (server_close (&srv) < 0) { + handle_error("server_close < 0"); } log_info ("remoted received a signal %d\n", signalnumber); @@ -95,8 +95,8 @@ int main(int argc, char **argv, char **env) else log_info ("remoted configuration loaded"); - if (srv_init (argc, argv, env, &srv, REMOTED_SERVICE_NAME) < 0) { - handle_error("srv_init < 0"); + if (server_init (argc, argv, env, &srv, REMOTED_SERVICE_NAME) < 0) { + handle_error("server_init < 0"); } 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); // the application will shut down, and remove the service unix socket - if (srv_close (&srv) < 0) { - handle_error("srv_close < 0"); + if (server_close (&srv) < 0) { + handle_error("server_close < 0"); } log_info ("remoted ended"); diff --git a/remote/lib/remotec.c b/remote/lib/remotec.c index 5342f20..fe1113d 100644 --- a/remote/lib/remotec.c +++ b/remote/lib/remotec.c @@ -9,11 +9,11 @@ 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); if (ret != 0) { - handle_err ("remote remotec_connection", "app_connection != 0"); + handle_err ("remote remotec_connection", "application_connection != 0"); } return ret; @@ -21,7 +21,7 @@ int remotec_connection (int argc, char **argv, char **env, 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) @@ -41,7 +41,7 @@ int remotec_msg_send (struct service *srv, const struct remoted_msg * m) return -1; } - app_write (srv, &m_data); + application_write (srv, &m_data); msg_free (&m_data); if (buf != NULL) @@ -65,7 +65,7 @@ int remotec_msg_recv (struct service *srv, struct remoted_msg *m) struct msg m_recv; 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); msg_free (&m_recv); diff --git a/remote/lib/remoted.c b/remote/lib/remoted.c index 4822a2e..b99550a 100644 --- a/remote/lib/remoted.c +++ b/remote/lib/remoted.c @@ -20,8 +20,8 @@ void handle_new_connection (struct service *srv, struct array_proc *ap) struct process *p = malloc(sizeof(struct process)); memset(p, 0, sizeof(struct process)); - if (srv_accept (srv, p) < 0) { - handle_error("srv_accept < 0"); + if (server_accept (srv, p) < 0) { + handle_error("server_accept < 0"); } else { 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)); int i; for (i = 0; i < proc_to_read->size; i++) { - if (srv_read (proc_to_read->tab_proc[i], &m) < 0) { - handle_error("srv_read < 0"); + if (server_read (proc_to_read->tab_proc[i], &m) < 0) { + handle_error("server_read < 0"); } 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); // close the connection to the process - if (srv_close_proc (p) < 0) - handle_error( "srv_close_proc < 0"); + if (server_close_proc (p) < 0) + handle_error( "server_close_proc < 0"); // remove the process from the processes list if (del_proc (ap, p) < 0) @@ -122,7 +122,7 @@ void remoted_main_loop (struct service *srv, struct remoted_ctx *ctx) while(1) { /* TODO: authorizations */ - ret = srv_select (&ap, srv, &proc_to_read); + ret = server_select (&ap, srv, &proc_to_read); if (ret == CONNECTION) { 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++) { - if (srv_close_proc (ap.tab_proc[i]) < 0) { - handle_error( "srv_close_proc < 0"); + if (server_close_proc (ap.tab_proc[i]) < 0) { + handle_error( "server_close_proc < 0"); } } } diff --git a/tcp/app/tcpd.c b/tcp/app/tcpd.c index 33dd360..5975ff6 100644 --- a/tcp/app/tcpd.c +++ b/tcp/app/tcpd.c @@ -15,7 +15,6 @@ #include #define PORT 6000 -#define TMPDIR "/tmp/ipc/" #define NBCLIENT 10 #define SERVICE_TCP "tcpd" #define LISTEN_BACKLOG 50 @@ -127,15 +126,15 @@ void * service_thread(void * c_data) { memset (&srv, 0, sizeof (struct service)); srv->index = 0; srv->version = 0; - srv_init (0, NULL, NULL, &srv, service, NULL); - if (app_srv_connection(&srv, piv, strlen(piv)) == -1) { - handle_error("app_srv_connection\n"); + server_init (0, NULL, NULL, &srv, service, NULL); + if (application_server_connection(&srv, piv, strlen(piv)) == -1) { + handle_error("application_server_connection\n"); } free(piv); /*struct process p; - app_create(&p, getpid(), cda->index, version); - srv_process_print(&p);*/ + application_create(&p, getpid(), cda->index, version); + server_process_print(&p);*/ //sleep(1); //printf("%s\n",p.path_proc ); /*if (proc_connection(&p) == -1){ @@ -165,7 +164,7 @@ void * service_thread(void * c_data) { if (FD_ISSET(srv.service_fd, &rdfs)){ nbytes = file_read(srv.service_fd, &buffer); if(nbytes < 0) { - perror("app_read()"); + perror("application_read()"); } printf("message from file : %s\n", buffer ); write_message(clientSock, buffer, nbytes); @@ -357,7 +356,7 @@ void * server_thread(void * reqq) { * listen = server for a service such as pongd * 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 *str = NULL; @@ -402,7 +401,7 @@ int srv_get_new_request(char *buf, info_request *req) { req->addr.sin_family = AF_INET; if (strcmp("connect", req->request) == 0) { - srv_process_gen (req->p, pid, index, version); + server_process_gen (req->p, pid, index, version); } return 1; @@ -515,7 +514,7 @@ void * client_thread(void *reqq) { int n = read_message(sock, buffer); if(n > 0) { 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"); } nbMessages--; @@ -528,7 +527,7 @@ void * client_thread(void *reqq) { break; } }else { - nbytes = app_read (req->p, &buffer); + nbytes = application_read (req->p, &buffer); printf("Client : message from app %d : %s\n",nbytes, buffer ); if ( nbytes == -1) { handle_error("file_read"); @@ -666,10 +665,10 @@ void main_loop (struct service *srv) { tab_req[nbclient].p = malloc(sizeof(struct 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; if (ret == -1) { - perror("srv_get_new_request()"); + perror("server_get_new_request()"); exit(1); } else if (ret == 0) { break; @@ -717,10 +716,10 @@ void main_loop (struct service *srv) { tab_req[nbclient].p = malloc(sizeof(struct 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; if (ret == -1) { - perror("srv_get_new_request()"); + perror("server_get_new_request()"); exit(1); } else if (ret == 0) { break; @@ -776,12 +775,12 @@ void main_loop (struct service *srv) { int main(int argc, char * argv[], char **env) { 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); // creates the service named pipe, that listens to client applications int ret; - if ((ret = srv_create (&srv))) { + if ((ret = server_create (&srv))) { fprintf(stdout, "error service_create %d\n", ret); exit (1); } @@ -791,7 +790,7 @@ int main(int argc, char * argv[], char **env) { main_loop (&srv); // 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); exit (1); } diff --git a/tcp/app/tcpd.h b/tcp/app/tcpd.h index 9cc71b8..27c7bea 100644 --- a/tcp/app/tcpd.h +++ b/tcp/app/tcpd.h @@ -48,7 +48,7 @@ void * server_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); diff --git a/tcp/test/tcpdtest.c b/tcp/test/tcpdtest.c index fea5ca8..1e2f618 100644 --- a/tcp/test/tcpdtest.c +++ b/tcp/test/tcpdtest.c @@ -9,11 +9,11 @@ do { perror(msg); exit(EXIT_FAILURE); } while (0) int main(int argc, char * argv[]) { - char *srv_message = malloc(BUFSIZ); + char *server_message = malloc(BUFSIZ); char *pidfile = 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()); char *proc_message = "hello frero"; @@ -38,7 +38,7 @@ int main(int argc, char * argv[]) { exit(errno); } //printf("connected...\n"); - file_write(sfd, srv_message, strlen(srv_message)); + file_write(sfd, server_message, strlen(server_message)); //printf("%s\n", proc_message); //sleep(1); file_write(sfd, proc_message, strlen(proc_message));