Obsolete
/
libipc-old
Archived
3
0
Fork 0

cleaning names

more_to_read
Philippe PITTOLI 2018-10-03 21:52:11 +02:00
parent 3eeb96b21d
commit aa98be0335
35 changed files with 231 additions and 231 deletions

View File

@ -28,14 +28,14 @@ int main (int argc, char *argv[], char *env[])
}
printf ("msg to send: %s\n", MSG);
msg_format_data (&m, MSG, strlen(MSG) +1);
ipc_message_format_data (&m, MSG, strlen(MSG) +1);
printf ("msg to send in the client: ");
print_msg (&m);
if (application_write (&srv, &m) < 0) {
handle_err("main", "application_write < 0");
return EXIT_FAILURE;
}
msg_free (&m);
ipc_message_free (&m);
if (application_read (&srv, &m) < 0) {
handle_err("main", "application_read < 0");
@ -43,7 +43,7 @@ int main (int argc, char *argv[], char *env[])
}
printf ("msg recv: %s\n", m.val);
msg_free (&m);
ipc_message_free (&m);
if (application_close (&srv) < 0) {
handle_err("main", "application_close < 0");

View File

@ -45,7 +45,7 @@ int main (int argc, char *argv[], char *env[])
handle_err("main", "server_write < 0");
return EXIT_FAILURE;
}
msg_free (&m);
ipc_message_free (&m);
// client quits
if (server_read (&p, &m) < 0) {
@ -58,7 +58,7 @@ int main (int argc, char *argv[], char *env[])
else {
fprintf (stderr, "err: should have received the client dis msg\n");
}
msg_free (&m);
ipc_message_free (&m);
if (server_close_proc (&p) < 0) {
handle_err("main", "server_close_proc < 0");

View File

@ -48,13 +48,13 @@ int ipc_server_accept (struct service *srv, struct process *p)
memset (&m_con, 0, sizeof (struct msg));
ipc_server_read (p, &m_con);
// TODO: handle the parameters in the first message
msg_free (&m_con);
ipc_message_free (&m_con);
struct msg m_ack;
memset (&m_ack, 0, sizeof (struct msg));
msg_format_ack (&m_ack, NULL, 0);
ipc_message_format_ack (&m_ack, NULL, 0);
ipc_server_write (p, &m_ack);
msg_free (&m_ack);
ipc_message_free (&m_ack);
return 0;
}
@ -71,8 +71,8 @@ int ipc_server_close_proc (struct process *p)
// 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 ("server_close_proc", "msg_write < 0");
// if (ipc_message_write (p->proc_fd, &m_ack_dis) < 0) {
// handle_err ("server_close_proc", "ipc_message_write < 0");
// }
return usock_close (p->proc_fd);
@ -80,12 +80,12 @@ int ipc_server_close_proc (struct process *p)
int ipc_server_read (const struct process *p, struct msg *m)
{
return msg_read (p->proc_fd, m);
return ipc_message_read (p->proc_fd, m);
}
int ipc_server_write (const struct process *p, const struct msg *m)
{
return msg_write (p->proc_fd, m);
return ipc_message_write (p->proc_fd, m);
}
int ipc_application_connection (int argc, char **argv, char **env
@ -113,14 +113,14 @@ int ipc_application_connection (int argc, char **argv, char **env
memset (&m_con, 0, sizeof (struct msg));
// format the connection msg
if (msg_format_con (&m_con, connectionstr, msize) < 0) {
handle_err ("application_connection", "msg_format_con");
if (ipc_message_format_con (&m_con, connectionstr, msize) < 0) {
handle_err ("application_connection", "ipc_message_format_con");
return -1;
}
// send connection msg
ipc_application_write (srv, &m_con);
msg_free (&m_con);
ipc_message_free (&m_con);
// receive ack msg
struct msg m_ack;
@ -129,7 +129,7 @@ int ipc_application_connection (int argc, char **argv, char **env
assert (m_ack.type == MSG_TYPE_ACK);
assert (m_ack.valsize == 0);
msg_free (&m_ack);
ipc_message_free (&m_ack);
return 0;
}
@ -140,8 +140,8 @@ 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 ("application_close", "msg_write < 0");
if (ipc_message_write (srv->service_fd, &m) < 0) {
handle_err ("application_close", "ipc_message_write < 0");
}
return usock_close (srv->service_fd);
@ -149,12 +149,12 @@ int ipc_application_close (struct service *srv)
int ipc_application_read (struct service *srv, struct msg *m)
{
return msg_read (srv->service_fd, m);
return ipc_message_read (srv->service_fd, m);
}
int ipc_application_write (struct service *srv, const struct msg *m)
{
return msg_write (srv->service_fd, m);
return ipc_message_write (srv->service_fd, m);
}

View File

@ -1,5 +1,5 @@
#ifndef __COMMUNICATION_H__
#define __COMMUNICATION_H__
#ifndef __IPC_COMMUNICATION_H__
#define __IPC_COMMUNICATION_H__
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,5 +1,5 @@
#ifndef __ERROR_H__
#define __ERROR_H__
#ifndef __IPC_ERROR_H__
#define __IPC_ERROR_H__
#include "logger.h"

View File

@ -1,5 +1,5 @@
#ifndef __LOGGER_H__
#define __LOGGER_H__
#ifndef __IPC_LOGGER_H__
#define __IPC_LOGGER_H__
#define LOG

View File

@ -4,13 +4,13 @@
#include <assert.h>
void print_msg (const struct msg *m)
void ipc_message_print (const struct msg *m)
{
assert (m != NULL);
printf ("msg: type %d len %d\n", m->type, m->valsize);
}
int msg_format_read (struct msg *m, const char *buf, size_t msize)
int ipc_message_format_read (struct msg *m, const char *buf, size_t msize)
{
assert (m != NULL);
assert (buf != NULL);
@ -37,7 +37,7 @@ int msg_format_read (struct msg *m, const char *buf, size_t msize)
return 0;
}
int msg_format_write (const struct msg *m, char **buf, size_t *msize)
int ipc_message_format_write (const struct msg *m, char **buf, size_t *msize)
{
assert (m != NULL);
assert (buf != NULL);
@ -68,7 +68,7 @@ int msg_format_write (const struct msg *m, char **buf, size_t *msize)
return 0;
}
int msg_read (int fd, struct msg *m)
int ipc_message_read (int fd, struct msg *m)
{
assert (m != NULL);
@ -81,7 +81,7 @@ int msg_read (int fd, struct msg *m)
return ret;
}
if (msg_format_read (m, buf, msize) < 0) {
if (ipc_message_format_read (m, buf, msize) < 0) {
return -1;
}
free (buf);
@ -89,13 +89,13 @@ int msg_read (int fd, struct msg *m)
return 0;
}
int msg_write (int fd, const struct msg *m)
int ipc_message_write (int fd, const struct msg *m)
{
assert (m != NULL);
char *buf = NULL;
size_t msize = 0;
msg_format_write (m, &buf, &msize);
ipc_message_format_write (m, &buf, &msize);
int ret = usock_send (fd, buf, msize);
if (ret < 0) {
@ -111,7 +111,7 @@ int msg_write (int fd, const struct msg *m)
// MSG FORMAT
int msg_format (struct msg *m, char type, const char *val, size_t valsize)
int ipc_message_format (struct msg *m, char type, const char *val, size_t valsize)
{
assert (m != NULL);
assert (valsize + 3 <= BUFSIZ);
@ -132,22 +132,22 @@ int msg_format (struct msg *m, char type, const char *val, size_t valsize)
return 0;
}
int msg_format_con (struct msg *m, const char *val, size_t valsize)
int ipc_message_format_con (struct msg *m, const char *val, size_t valsize)
{
return msg_format (m, MSG_TYPE_CON, val, valsize);
return ipc_message_format (m, MSG_TYPE_CON, val, valsize);
}
int msg_format_data (struct msg *m, const char *val, size_t valsize)
int ipc_message_format_data (struct msg *m, const char *val, size_t valsize)
{
return msg_format (m, MSG_TYPE_DATA, val, valsize);
return ipc_message_format (m, MSG_TYPE_DATA, val, valsize);
}
int msg_format_ack (struct msg *m, const char *val, size_t valsize)
int ipc_message_format_ack (struct msg *m, const char *val, size_t valsize)
{
return msg_format (m, MSG_TYPE_ACK, val, valsize);
return ipc_message_format (m, MSG_TYPE_ACK, val, valsize);
}
int msg_free (struct msg *m)
int ipc_message_free (struct msg *m)
{
assert (m != NULL);

View File

@ -1,5 +1,5 @@
#ifndef __MSG_H__
#define __MSG_H__
#ifndef __IPC_MSG_H__
#define __IPC_MSG_H__
#include <stdio.h>
#include <stdlib.h>
@ -18,20 +18,20 @@ struct msg {
};
// used to create msg structure from buffer
int msg_format_read (struct msg *m, const char *buf, size_t msize);
int ipc_message_format_read (struct msg *m, const char *buf, size_t msize);
// used to create buffer from msg structure
int msg_format_write (const struct msg *m, char **buf, size_t *msize);
int ipc_message_format_write (const struct msg *m, char **buf, size_t *msize);
// read a structure msg from fd
int msg_read (int fd, struct msg *m);
int ipc_message_read (int fd, struct msg *m);
// write a structure msg to fd
int msg_write (int fd, const struct msg *m);
int ipc_message_write (int fd, const struct msg *m);
int msg_format_con (struct msg *m, const char *val, size_t valsize);
int msg_format_data (struct msg *m, const char *val, size_t valsize);
int msg_format_ack (struct msg *m, const char *val, size_t valsize);
int ipc_message_format_con (struct msg *m, const char *val, size_t valsize);
int ipc_message_format_data (struct msg *m, const char *val, size_t valsize);
int ipc_message_format_ack (struct msg *m, const char *val, size_t valsize);
int msg_free (struct msg *m);
void print_msg (const struct msg *m);
int ipc_message_free (struct msg *m);
void ipc_message_print (const struct msg *m);
#endif

View File

@ -5,7 +5,7 @@
#include <string.h>
struct process * server_process_copy (const struct process *p)
struct process * ipc_server_process_copy (const struct process *p)
{
if (p == NULL)
return NULL;
@ -16,13 +16,13 @@ struct process * server_process_copy (const struct process *p)
return copy;
}
int server_process_eq (const struct process *p1, const struct process *p2)
int ipc_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 server_process_gen (struct process *p
void ipc_server_process_gen (struct process *p
, unsigned int index, unsigned int version)
{
p->version = version;

View File

@ -1,5 +1,5 @@
#ifndef __PROCESS_H__
#define __PROCESS_H__
#ifndef __IPC_PROCESS_H__
#define __IPC_PROCESS_H__
struct process {
unsigned int version;
@ -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 * server_process_copy (const struct process *p);
int server_process_eq (const struct process *p1, const struct process *p2);
struct process * ipc_server_process_copy (const struct process *p);
int ipc_server_process_eq (const struct process *p1, const struct process *p2);
// create the service process structure
void server_process_gen (struct process *p
void ipc_server_process_gen (struct process *p
, unsigned int index, unsigned int version);
void process_print (struct process *);

View File

@ -1,5 +1,5 @@
#ifndef __USOCKET_H__
#define __USOCKET_H__
#ifndef __IPC_USOCKET_H__
#define __IPC_USOCKET_H__
#include <time.h>
#include <sys/socket.h>

View File

@ -1,5 +1,5 @@
#ifndef __UTIL_H__
#define __UTIL_H__
#ifndef __IPC_UTIL_H__
#define __IPC_UTIL_H__
#include <stdio.h>
#include <stdlib.h>

View File

@ -12,7 +12,7 @@ int main(int argc, char * argv[], char *env[])
{
struct service srv;
memset (&srv, 0, sizeof (struct service));
server_init (argc, argv, env, &srv, SERVICE, NULL);
ipc_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

View File

@ -5,31 +5,31 @@ communication.h \- all functions explained
.nf
.B #include <communication.h>
.sp
.BI "int server_init (int "argc ", char **" argv ", char **" env ", struct service *" srv "
.BI "int ipc_server_init (int "argc ", char **" argv ", char **" env ", struct service *" srv "
.BI " , const char *" service_name );
.BI "int server_accept (struct service *" srv ", struct process *" p );
.BI "int ipc_server_accept (struct service *" srv ", struct process *" p );
.sp
.BI "int server_read (const struct process *" p ", struct msg *" message );
.BI "int server_write (const struct process *" p ", const struct msg *" message );
.BI "int ipc_server_read (const struct process *" p ", struct msg *" message );
.BI "int ipc_server_write (const struct process *" p ", const struct msg *" message );
.sp
.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 ipc_server_close (struct service *" srv );
.BI "int ipc_server_close_proc (struct process *" p );
.BI "int ipc_server_select (struct array_proc *" fds ", struct service *" srv ", struct array_proc *" readfds );
.BI "int application_connection (int " argc ", char **" argv ", char **" env ", struct service *" srv
.BI "int ipc_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 application_read (const struct service *" srv ", struct msg *" message );
.BI "int application_write (const struct service *" srv ", const struct msg *" message );
.BI "int ipc_application_read (const struct service *" srv ", struct msg *" message );
.BI "int ipc_application_write (const struct service *" srv ", const struct msg *" message );
.sp
.BI "int application_close (struct service *" srv );
.BI "int ipc_application_close (struct service *" srv );
.fi
.SH DESCRIPTION
The
.BR server_init ()
.BR ipc_server_init ()
function let the service declare itself, create a new unix socket and listen.
.I argc
,
@ -43,25 +43,25 @@ is the pointer to the \fBstruct service\fR that should be filled (index and vers
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 server_accept ()
.BR ipc_server_accept ()
function accepts new connections.
.IR p
parameter is the client process that will be provided after the connection.
.PP
The
.BR server_read ()
.BR ipc_server_read ()
and
.BR server_write ()
.BR ipc_server_write ()
functions take respectively a message to read from, and a message to write to a process.
.PP
The
.BR server_close_proc ()
.BR ipc_server_close_proc ()
and
.BR server_close ()
.BR ipc_server_close ()
functions terminate respectively a process (closing its unix socket) and the service (closing and removing its named unix socket).
.PP
The
.BR server_select ()
.BR ipc_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 application_connection ()
.BR ipc_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 application_read ()
.BR ipc_application_read ()
and
.BR application_write ()
.BR ipc_application_write ()
functions take respectively a message to read from, and a message to write to the service.
.PP
The
.BR application_close ()
.BR ipc_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 server_select()
.BR ipc_server_select()
if there is a new connection, the function will return \fBCONNECTION\fR, if there is one or more processes talking the function will return \fBAPPLICATION\fR and finally if there are both a new connection and a process talking the function will return \fBCON_APP\fR.

View File

@ -28,14 +28,14 @@ void non_interactive (int argc, char *argv[], char *env[])
}
printf ("msg to send: %s\n", MSG);
msg_format_data (&m, MSG, strlen(MSG) +1);
ipc_message_format_data (&m, MSG, strlen(MSG) +1);
printf ("msg to send in the client: ");
print_msg (&m);
ipc_message_print (&m);
if (ipc_application_write (&srv, &m) < 0) {
handle_err("main", "application_write < 0");
exit (EXIT_FAILURE);
}
msg_free (&m);
ipc_message_free (&m);
if (ipc_application_read (&srv, &m) < 0) {
handle_err("main", "application_read < 0");
@ -43,7 +43,7 @@ void non_interactive (int argc, char *argv[], char *env[])
}
printf ("msg recv: %s\n", m.val);
msg_free (&m);
ipc_message_free (&m);
if (ipc_application_close (&srv) < 0) {
handle_err("main", "application_close < 0");
@ -80,7 +80,7 @@ void interactive (int argc, char *argv[], char *env[])
if (n == 0 || strncmp (buf, "exit", 4) == 0)
break;
msg_format_data (&m, buf, strlen(buf) +1);
ipc_message_format_data (&m, buf, strlen(buf) +1);
memset (buf, 0, BUFSIZ);
// print_msg (&m);
@ -89,7 +89,7 @@ void interactive (int argc, char *argv[], char *env[])
handle_err("main", "application_write < 0");
exit (EXIT_FAILURE);
}
msg_free (&m);
ipc_message_free (&m);
if (ipc_application_read (&srv, &m) < 0) {
handle_err("main", "application_read < 0");
@ -97,7 +97,7 @@ void interactive (int argc, char *argv[], char *env[])
}
printf ("msg recv: %s", m.val);
msg_free (&m);
ipc_message_free (&m);
}
if (ipc_application_close (&srv) < 0) {

View File

@ -38,11 +38,11 @@ void * listener (void *params)
struct pubsub_msg m;
memset (&m, 0, sizeof (struct pubsub_msg));
pubsub_msg_recv (srv, &m);
pubsub_message_recv (srv, &m);
printf ("\r\033[31m>\033[00m %s\n", m.data);
print_cmd ();
pubsub_msg_free (&m);
pubsub_message_free (&m);
}
pthread_exit (NULL);
@ -61,10 +61,10 @@ void chan_sub (struct service *srv, char *chan)
strncpy (msg.chan, chan, msg.chanlen);
msg.chan[strlen (chan)] = '\0';
pubsub_msg_send (srv, &msg);
pubsub_message_send (srv, &msg);
printf ("subscribed to %s\n", chan);
pubsub_msg_free (&msg);
pubsub_message_free (&msg);
}
void main_loop (int argc, char **argv, char **env
@ -128,14 +128,14 @@ void main_loop (int argc, char **argv, char **env
strncpy ((char *) msg.data, buf, msg.datalen);
msg.data[strlen(buf)] = '\0';
pubsub_msg_send (&srv, &msg);
pubsub_message_send (&srv, &msg);
free (msg.data);
msg.data = NULL;
msg.datalen = 0;
}
// free everything
pubsub_msg_free (&msg);
pubsub_message_free (&msg);
pthread_cancel (thr);
pthread_join (thr, NULL);

View File

@ -5,25 +5,25 @@
#include "msg.h"
#include "../../core/error.h"
void pubsub_msg_serialize (const struct pubsub_msg *msg, char **data, size_t *len)
void pubsub_message_serialize (const struct pubsub_msg *msg, char **data, size_t *len)
{
if (msg == NULL) {
handle_err ("pubsub_msg_serialize", "msg == NULL");
handle_err ("pubsub_message_serialize", "msg == NULL");
return;
}
if (data == NULL) {
handle_err ("pubsub_msg_serialize", "data == NULL");
handle_err ("pubsub_message_serialize", "data == NULL");
return;
}
if (*data != NULL) {
handle_err ("pubsub_msg_serialize", "*data != NULL");
handle_err ("pubsub_message_serialize", "*data != NULL");
return;
}
if (len == NULL) {
handle_err ("pubsub_msg_serialize", "len == NULL");
handle_err ("pubsub_message_serialize", "len == NULL");
return;
}
@ -31,7 +31,7 @@ void pubsub_msg_serialize (const struct pubsub_msg *msg, char **data, size_t *le
size_t buflen = 1 + 2 * sizeof (size_t) + msg->chanlen + msg->datalen;
if (buflen > BUFSIZ) {
handle_err ("pubsub_msg_serialize", "chanlen + datalen too high");
handle_err ("pubsub_message_serialize", "chanlen + datalen too high");
return;
}
@ -59,17 +59,17 @@ void pubsub_msg_serialize (const struct pubsub_msg *msg, char **data, size_t *le
*len = buflen;
}
void pubsub_msg_unserialize (struct pubsub_msg *msg, const char *buf, size_t mlen)
void pubsub_message_unserialize (struct pubsub_msg *msg, const char *buf, size_t mlen)
{
if (msg == NULL) {
handle_err ("pubsub_msg_unserialize", "msg == NULL");
handle_err ("pubsub_message_unserialize", "msg == NULL");
return;
}
pubsub_msg_free (msg);
pubsub_message_free (msg);
if (mlen > BUFSIZ) {
handle_err ("pubsub_msg_unserialize", "mlen > BUFSIZ");
handle_err ("pubsub_message_unserialize", "mlen > BUFSIZ");
return;
}
@ -81,7 +81,7 @@ void pubsub_msg_unserialize (struct pubsub_msg *msg, const char *buf, size_t mle
// chan
memcpy (&msg->chanlen, buf + offset, sizeof (size_t));
if (msg->chanlen > BUFSIZ) {
handle_err ("pubsub_msg_unserialize", "chanlen > BUFSIZ");
handle_err ("pubsub_message_unserialize", "chanlen > BUFSIZ");
return;
}
msg->chan = malloc (msg->chanlen);
@ -93,7 +93,7 @@ void pubsub_msg_unserialize (struct pubsub_msg *msg, const char *buf, size_t mle
// data
memcpy (&msg->datalen, buf + offset, sizeof (size_t));
if (msg->datalen > BUFSIZ) {
handle_err ("pubsub_msg_unserialize", "datalen > BUFSIZ");
handle_err ("pubsub_message_unserialize", "datalen > BUFSIZ");
return;
}
msg->data = malloc (msg->datalen);
@ -103,10 +103,10 @@ void pubsub_msg_unserialize (struct pubsub_msg *msg, const char *buf, size_t mle
offset += msg->datalen;
}
void pubsub_msg_free (struct pubsub_msg *msg)
void pubsub_message_free (struct pubsub_msg *msg)
{
if (msg == NULL) {
handle_err ("pubsub_msg_free", "msg == NULL");
handle_err ("pubsub_message_free", "msg == NULL");
return;
}
@ -120,10 +120,10 @@ void pubsub_msg_free (struct pubsub_msg *msg)
}
}
void pubsub_msg_print (const struct pubsub_msg *msg)
void pubsub_message_print (const struct pubsub_msg *msg)
{
if (msg == NULL) {
handle_err ("pubsub_msg_print", "msg == NULL");
handle_err ("pubsub_message_print", "msg == NULL");
return;
}

View File

@ -13,9 +13,9 @@ struct pubsub_msg {
size_t datalen;
};
void pubsub_msg_serialize (const struct pubsub_msg *msg, char **data, size_t *len);
void pubsub_msg_unserialize (struct pubsub_msg *msg, const char *data, size_t len);
void pubsub_msg_free (struct pubsub_msg *msg);
void pubsub_msg_print (const struct pubsub_msg *msg);
void pubsub_message_serialize (const struct pubsub_msg *msg, char **data, size_t *len);
void pubsub_message_unserialize (struct pubsub_msg *msg, const char *data, size_t len);
void pubsub_message_free (struct pubsub_msg *msg);
void pubsub_message_print (const struct pubsub_msg *msg);
#endif

View File

@ -29,14 +29,14 @@ void pubsub_quit (struct service *srv)
// line fmt : 0 0 0 quit
char line[BUFSIZ];
snprintf (line, BUFSIZ, "0 0 0 quit\n");
application_server_connection (srv, line, strlen (line));
ipc_application_server_connection (srv, line, strlen (line));
}
#endif
int pubsub_connection (int argc, char **argv, char **env
, struct service *srv)
{
int ret = application_connection (argc, argv, env
int ret = ipc_application_connection (argc, argv, env
, srv, PUBSUBD_SERVICE_NAME, NULL, 0);
if (ret != 0) {
@ -48,28 +48,28 @@ int pubsub_connection (int argc, char **argv, char **env
int pubsub_disconnect (struct service *srv)
{
return application_close (srv);
return ipc_application_close (srv);
}
int pubsub_msg_send (struct service *srv, const struct pubsub_msg * m)
int pubsub_message_send (struct service *srv, const struct pubsub_msg * m)
{
size_t msize = 0;
char * buf = NULL;
pubsub_msg_serialize (m, &buf, &msize);
pubsub_message_serialize (m, &buf, &msize);
struct msg m_data;
memset (&m_data, 0, sizeof (struct msg));
// format the connection msg
if (msg_format_data (&m_data, buf, msize) < 0) {
handle_err ("pubsub_msg_send", "msg_format_data");
handle_err ("pubsub_message_send", "msg_format_data");
if (buf != NULL)
free (buf);
return -1;
}
application_write (srv, &m_data);
msg_free (&m_data);
ipc_application_write (srv, &m_data);
ipc_message_free (&m_data);
if (buf != NULL)
free(buf);
@ -77,25 +77,25 @@ int pubsub_msg_send (struct service *srv, const struct pubsub_msg * m)
return 0;
}
int pubsub_msg_recv (struct service *srv, struct pubsub_msg *m)
int pubsub_message_recv (struct service *srv, struct pubsub_msg *m)
{
if (srv == NULL) {
handle_err ("pubsub_msg_recv", "srv == NULL");
handle_err ("pubsub_message_recv", "srv == NULL");
return -1;
}
if (m == NULL) {
handle_err ("pubsub_msg_recv", "m == NULL");
handle_err ("pubsub_message_recv", "m == NULL");
return -1;
}
struct msg m_recv;
memset (&m_recv, 0, sizeof (struct msg));
application_read (srv, &m_recv);
pubsub_msg_unserialize (m, m_recv.val, m_recv.valsize);
ipc_application_read (srv, &m_recv);
pubsub_message_unserialize (m, m_recv.val, m_recv.valsize);
msg_free (&m_recv);
ipc_message_free (&m_recv);
return 0;
}

View File

@ -17,8 +17,8 @@ enum subscriber_action {PUBSUB_QUIT = 1, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH};
int pubsub_connection (int argc, char **argv, char **env, struct service *srv);
int pubsub_disconnect (struct service *srv);
int pubsub_msg_send (struct service *srv, const struct pubsub_msg * m);
int pubsub_msg_recv (struct service *srv, struct pubsub_msg *m);
int pubsub_message_send (struct service *srv, const struct pubsub_msg * m);
int pubsub_message_recv (struct service *srv, struct pubsub_msg *m);
// TODO
void pubsub_quit (struct service *srv);

View File

@ -25,17 +25,17 @@ void pubsubd_send (const struct array_proc *ap, const struct pubsub_msg * m)
char *buf = NULL;
size_t msize = 0;
pubsub_msg_serialize (m, &buf, &msize);
pubsub_message_serialize (m, &buf, &msize);
struct msg m_data;
memset (&m_data, 0, sizeof (struct msg));
msg_format_data (&m_data, buf, msize);
ipc_message_format_data (&m_data, buf, msize);
int i;
for (i = 0; i < ap->size ; i++) {
server_write (ap->tab_proc[i], &m_data);
ipc_server_write (ap->tab_proc[i], &m_data);
}
msg_free (&m_data);
ipc_message_free (&m_data);
if (buf != NULL) {
free (buf);
@ -48,11 +48,11 @@ 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
// server_read (p, &m_data);
// ipc_server_read (p, &m_data);
//
// pubsub_msg_unserialize (m, m_data.val, m_data.valsize);
// pubsub_message_unserialize (m, m_data.val, m_data.valsize);
//
// msg_free (&m_data);
// ipc_message_free (&m_data);
// }
/**
@ -109,7 +109,7 @@ void handle_new_msg (struct channels *chans
if (del_proc (proc_to_read, p) < 0)
handle_err( "handle_new_msg", "del_proc < 0");
msg_free (&m);
ipc_message_free (&m);
// free process
free (p);
@ -121,7 +121,7 @@ void handle_new_msg (struct channels *chans
struct pubsub_msg m_data;
memset (&m_data, 0, sizeof (struct pubsub_msg));
pubsub_msg_unserialize (&m_data, m.val, m.valsize);
pubsub_message_unserialize (&m_data, m.val, m.valsize);
if (m_data.type == PUBSUB_MSG_TYPE_SUB) {
printf ("proc %d subscribing to %s\n"
@ -146,14 +146,14 @@ void handle_new_msg (struct channels *chans
struct channel *chan = pubsubd_channel_search (chans, m_data.chan);
if (chan == NULL) {
handle_err ("handle_new_msg", "publish on nonexistent channel");
msg_free (&m);
ipc_message_free (&m);
return ;
}
pubsubd_send (chan->subs, &m_data);
}
pubsub_msg_free (&m_data);
msg_free (&m);
pubsub_message_free (&m_data);
ipc_message_free (&m);
}
}
@ -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 = server_select (&ap, srv, &proc_to_read);
ret = ipc_server_select (&ap, srv, &proc_to_read);
if (ret == CONNECTION) {
handle_new_connection (srv, &ap);

View File

@ -10,6 +10,6 @@
#define PUBSUBD_SERVICE_NAME "pubsubd"
void pubsubd_main_loop (struct service *srv, struct channels * chans);
void pubsubd_msg_send (const struct array_proc *ap, const struct pubsub_msg * m);
void pubsubd_message_send (const struct array_proc *ap, const struct pubsub_msg * m);
#endif

View File

@ -129,7 +129,7 @@ void * pubsubd_worker_thread (void *params)
struct pubsub_msg m;
memset (&m, 0, sizeof (struct pubsub_msg));
pubsub_msg_recv (ale->p, &m);
pubsub_message_recv (ale->p, &m);
if (m.type == PUBSUB_TYPE_DISCONNECT) {
// printf ("process %d disconnecting...\n", ale->p->pid);
@ -145,13 +145,13 @@ void * pubsubd_worker_thread (void *params)
}
else {
printf ("what should be sent: ");
pubsub_msg_print (&m);
pubsub_message_print (&m);
printf ("send the message to:\t");
pubsubd_channel_print (ch);
pubsub_msg_send (ch->alh, &m);
pubsub_message_send (ch->alh, &m);
}
}
pubsub_msg_free (&m);
pubsub_message_free (&m);
}
pubsubd_subscriber_free (ale);

View File

@ -30,24 +30,24 @@ int main(int argc, char * argv[])
memcpy (msg.data, DATA, msg.datalen);
printf ("msg 1: ");
pubsub_msg_print (&msg);
pubsub_message_print (&msg);
char *buffer = NULL;
size_t len = 0;
pubsub_msg_serialize (&msg, &buffer, &len);
pubsub_message_serialize (&msg, &buffer, &len);
mprint_hexa ("buffer msg 1", (unsigned char *) buffer, len);
struct pubsub_msg msg2;
memset (&msg2, 0, sizeof (struct pubsub_msg));
pubsub_msg_unserialize (&msg2, buffer, len);
pubsub_message_unserialize (&msg2, buffer, len);
printf ("msg 2: ");
pubsub_msg_print (&msg2);
pubsub_message_print (&msg2);
pubsub_msg_free (&msg);
pubsub_msg_free (&msg2);
pubsub_message_free (&msg);
pubsub_message_free (&msg2);
if (buffer != NULL)
free (buffer);

View File

@ -26,7 +26,7 @@ void sim_connection (int argc, char **argv, char **env, pid_t pid, int index, in
struct service srv;
memset (&srv, 0, sizeof (struct service));
server_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
ipc_server_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
printf ("Writing on %s.\n", srv.spath);
struct process p;
@ -58,15 +58,15 @@ void sim_connection (int argc, char **argv, char **env, pid_t pid, int index, in
m.datalen = strlen (MYMESSAGE);
printf ("send message\n");
pubsub_msg_send (&p, &m);
pubsub_message_send (&p, &m);
}
else {
pubsub_msg_recv (&p, &m);
pubsubd_msg_print (&m);
pubsub_message_recv (&p, &m);
pubsubd_message_print (&m);
}
// free everything
pubsubd_msg_free (&m);
pubsubd_message_free (&m);
printf ("disconnection\n");
// disconnect from the server
@ -82,14 +82,14 @@ void sim_disconnection (int argc, char **argv, char **env, pid_t pid, int index,
{
struct service srv;
memset (&srv, 0, sizeof (struct service));
server_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
ipc_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
server_process_gen (&p, pid, index, version);
ipc_server_process_gen (&p, pid, index, version);
// send a message to disconnect
// line : pid index version action chan

View File

@ -19,7 +19,7 @@ main(int argc, char **argv, char **env)
{
struct service srv;
memset (&srv, 0, sizeof (struct service));
server_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
ipc_server_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
printf ("Writing on %s.\n", srv.spath);
struct process p;
@ -44,15 +44,15 @@ main(int argc, char **argv, char **env)
m.chanlen = strlen (MYCHAN);
m.data = malloc (strlen (MYMESSAGE));
m.datalen = strlen (MYMESSAGE);
pubsub_msg_send (&p, &m);
pubsub_message_send (&p, &m);
// second message, to disconnect from the server
m.type = PUBSUB_TYPE_DISCONNECT;
pubsub_msg_send (&p, &m);
pubsub_message_send (&p, &m);
// free everything
pubsubd_msg_free (&m);
pubsubd_message_free (&m);
// the application will shut down, and remove the application named pipes
if (application_destroy (&p))

View File

@ -47,11 +47,11 @@ void * listener (void *params)
struct remoted_msg m;
memset (&m, 0, sizeof (struct remoted_msg));
remote_msg_recv (srv, &m);
remote_message_recv (srv, &m);
printf ("\r\033[31m>\033[00m %s\n", m.data);
print_cmd ();
remote_msg_free (&m);
remote_message_free (&m);
}
pthread_exit (NULL);
@ -90,14 +90,14 @@ void main_loop (int argc, char **argv, char **env
strncpy ((char *) msg.data, "salut", msg.datalen);
/* TODO */
remotec_msg_send (&srv, &msg);
remotec_message_send (&srv, &msg);
free (msg.data);
msg.data = NULL;
msg.datalen = 0;
}
// free everything
remote_msg_free (&msg);
remote_message_free (&msg);
#endif
log_debug ("remotec disconnection...");

View File

@ -5,25 +5,25 @@
#include "msg.h"
#include "../../core/error.h"
void remote_msg_serialize (const struct remoted_msg *msg, char **data, size_t *len)
void remote_message_serialize (const struct remoted_msg *msg, char **data, size_t *len)
{
if (msg == NULL) {
handle_err ("remote remote_msg_serialize", "msg == NULL");
handle_err ("remote remote_message_serialize", "msg == NULL");
return;
}
if (data == NULL) {
handle_err ("remote remote_msg_serialize", "data == NULL");
handle_err ("remote remote_message_serialize", "data == NULL");
return;
}
if (*data != NULL) {
handle_err ("remote remote_msg_serialize", "*data != NULL");
handle_err ("remote remote_message_serialize", "*data != NULL");
return;
}
if (len == NULL) {
handle_err ("remote remote_msg_serialize", "len == NULL");
handle_err ("remote remote_message_serialize", "len == NULL");
return;
}
@ -31,7 +31,7 @@ void remote_msg_serialize (const struct remoted_msg *msg, char **data, size_t *l
size_t buflen = 1 + sizeof (size_t) + msg->datalen;
if (buflen > BUFSIZ) {
handle_err ("remote remote_msg_serialize", "datalen too high");
handle_err ("remote remote_message_serialize", "datalen too high");
return;
}
@ -53,17 +53,17 @@ void remote_msg_serialize (const struct remoted_msg *msg, char **data, size_t *l
*len = buflen;
}
void remote_msg_unserialize (struct remoted_msg *msg, const char *buf, size_t mlen)
void remote_message_unserialize (struct remoted_msg *msg, const char *buf, size_t mlen)
{
if (msg == NULL) {
handle_err ("remote remote_msg_unserialize", "msg == NULL");
handle_err ("remote remote_message_unserialize", "msg == NULL");
return;
}
remote_msg_free (msg);
remote_message_free (msg);
if (mlen > BUFSIZ) {
handle_err ("remote remote_msg_unserialize", "mlen > BUFSIZ");
handle_err ("remote remote_message_unserialize", "mlen > BUFSIZ");
return;
}
@ -75,7 +75,7 @@ void remote_msg_unserialize (struct remoted_msg *msg, const char *buf, size_t ml
// data
memcpy (&msg->datalen, buf + offset, sizeof (size_t));
if (msg->datalen > BUFSIZ) {
handle_err ("remote remote_msg_unserialize", "datalen > BUFSIZ");
handle_err ("remote remote_message_unserialize", "datalen > BUFSIZ");
return;
}
msg->data = malloc (msg->datalen);
@ -85,10 +85,10 @@ void remote_msg_unserialize (struct remoted_msg *msg, const char *buf, size_t ml
offset += msg->datalen;
}
void remote_msg_free (struct remoted_msg *msg)
void remote_message_free (struct remoted_msg *msg)
{
if (msg == NULL) {
handle_err ("remote remote_msg_free", "msg == NULL");
handle_err ("remote remote_message_free", "msg == NULL");
return;
}
@ -98,10 +98,10 @@ void remote_msg_free (struct remoted_msg *msg)
}
}
void remote_msg_print (const struct remoted_msg *msg)
void remote_message_print (const struct remoted_msg *msg)
{
if (msg == NULL) {
handle_err ("remote remote_msg_print", "msg == NULL");
handle_err ("remote remote_message_print", "msg == NULL");
return;
}

View File

@ -11,10 +11,10 @@ struct remoted_msg {
size_t datalen;
};
void remote_msg_serialize (const struct remoted_msg *msg, char **data, size_t *len);
void remote_msg_unserialize (struct remoted_msg *msg, const char *data, size_t len);
void remote_message_serialize (const struct remoted_msg *msg, char **data, size_t *len);
void remote_message_unserialize (struct remoted_msg *msg, const char *data, size_t len);
void remote_msg_free (struct remoted_msg *msg);
void remote_msg_print (const struct remoted_msg *msg);
void remote_message_free (struct remoted_msg *msg);
void remote_message_print (const struct remoted_msg *msg);
#endif

View File

@ -9,7 +9,7 @@
int remotec_connection (int argc, char **argv, char **env, struct service *srv)
{
int ret = application_connection (argc, argv, env
int ret = ipc_application_connection (argc, argv, env
, srv, REMOTED_SERVICE_NAME, NULL, 0);
if (ret != 0) {
@ -21,28 +21,28 @@ int remotec_connection (int argc, char **argv, char **env, struct service *srv)
int remotec_disconnection (struct service *srv)
{
return application_close (srv);
return ipc_application_close (srv);
}
int remotec_msg_send (struct service *srv, const struct remoted_msg * m)
int remotec_message_send (struct service *srv, const struct remoted_msg * m)
{
size_t msize = 0;
char * buf = NULL;
remote_msg_serialize (m, &buf, &msize);
remote_message_serialize (m, &buf, &msize);
struct msg m_data;
memset (&m_data, 0, sizeof (struct msg));
// format the connection msg
if (msg_format_data (&m_data, buf, msize) < 0) {
handle_err ("remotec_msg_send", "msg_format_data");
handle_err ("remotec_message_send", "msg_format_data");
if (buf != NULL)
free (buf);
return -1;
}
application_write (srv, &m_data);
msg_free (&m_data);
ipc_application_write (srv, &m_data);
ipc_message_free (&m_data);
if (buf != NULL)
free(buf);
@ -50,25 +50,25 @@ int remotec_msg_send (struct service *srv, const struct remoted_msg * m)
return 0;
}
int remotec_msg_recv (struct service *srv, struct remoted_msg *m)
int remotec_message_recv (struct service *srv, struct remoted_msg *m)
{
if (srv == NULL) {
handle_err ("remotec_msg_recv", "srv == NULL");
handle_err ("remotec_message_recv", "srv == NULL");
return -1;
}
if (m == NULL) {
handle_err ("remotec_msg_recv", "m == NULL");
handle_err ("remotec_message_recv", "m == NULL");
return -1;
}
struct msg m_recv;
memset (&m_recv, 0, sizeof (struct msg));
application_read (srv, &m_recv);
remote_msg_unserialize (m, m_recv.val, m_recv.valsize);
ipc_application_read (srv, &m_recv);
remote_message_unserialize (m, m_recv.val, m_recv.valsize);
msg_free (&m_recv);
ipc_message_free (&m_recv);
return 0;
}

View File

@ -10,7 +10,7 @@
int remotec_connection (int argc, char **argv, char **env, struct service *srv);
int remotec_disconnection (struct service *srv);
int remotec_msg_send (struct service *srv, const struct remoted_msg *msg);
int remotec_msg_recv (struct service *srv, struct remoted_msg *msg);
int remotec_message_send (struct service *srv, const struct remoted_msg *msg);
int remotec_message_recv (struct service *srv, struct remoted_msg *msg);
#endif

View File

@ -59,7 +59,7 @@ void handle_new_msg (struct array_proc *ap, struct array_proc *proc_to_read)
if (del_proc (proc_to_read, p) < 0)
handle_err( "handle_new_msg", "del_proc < 0");
msg_free (&m);
ipc_message_free (&m);
// free process
free (p);
@ -72,7 +72,7 @@ void handle_new_msg (struct array_proc *ap, struct array_proc *proc_to_read)
struct pubsub_msg m_data;
memset (&m_data, 0, sizeof (struct pubsub_msg));
pubsub_msg_unserialize (&m_data, m.val, m.valsize);
pubsub_message_unserialize (&m_data, m.val, m.valsize);
if (m_data.type == PUBSUB_MSG_TYPE_SUB) {
printf ("proc %d subscribing to %s\n"
@ -97,15 +97,15 @@ void handle_new_msg (struct array_proc *ap, struct array_proc *proc_to_read)
struct channel *chan = pubsubd_channel_search (chans, m_data.chan);
if (chan == NULL) {
handle_err ("handle_new_msg", "publish on nonexistent channel");
msg_free (&m);
ipc_message_free (&m);
return ;
}
pubsubd_send (chan->subs, &m_data);
}
pubsub_msg_free (&m_data);
pubsub_message_free (&m_data);
#endif
msg_free (&m);
ipc_message_free (&m);
}
}
@ -122,7 +122,7 @@ void remoted_main_loop (struct service *srv, struct remoted_ctx *ctx)
while(1) {
/* TODO: authorizations */
ret = server_select (&ap, srv, &proc_to_read);
ret = ipc_server_select (&ap, srv, &proc_to_read);
if (ret == CONNECTION) {
handle_new_connection (srv, &ap);

View File

@ -126,15 +126,15 @@ void * service_thread(void * c_data) {
memset (&srv, 0, sizeof (struct service));
srv->index = 0;
srv->version = 0;
server_init (0, NULL, NULL, &srv, service, NULL);
ipc_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;
application_create(&p, getpid(), cda->index, version);
server_process_print(&p);*/
ipc_application_create(&p, getpid(), cda->index, version);
ipc_server_process_print(&p);*/
//sleep(1);
//printf("%s\n",p.path_proc );
/*if (proc_connection(&p) == -1){
@ -272,7 +272,7 @@ void makePivMessage (char ** piv, int pid, int index, int version) {
* lancer le serveur, ecouter sur une l'adresse et port
* A chaque nouveau client lance un thread service
*/
void * server_thread(void * reqq) {
void * ipc_server_thread(void * reqq) {
info_request *req = (info_request*) reqq;
//client
@ -356,7 +356,7 @@ void * server_thread(void * reqq) {
* listen = server for a service such as pongd
* connect = connect to a server
*/
int server_get_new_request(char *buf, info_request *req) {
int ipc_server_get_new_request(char *buf, info_request *req) {
char *token = NULL, *saveptr = NULL;
char *str = NULL;
@ -401,7 +401,7 @@ int server_get_new_request(char *buf, info_request *req) {
req->addr.sin_family = AF_INET;
if (strcmp("connect", req->request) == 0) {
server_process_gen (req->p, pid, index, version);
ipc_server_process_gen (req->p, pid, index, version);
}
return 1;
@ -527,7 +527,7 @@ void * client_thread(void *reqq) {
break;
}
}else {
nbytes = application_read (req->p, &buffer);
nbytes = ipc_application_read (req->p, &buffer);
printf("Client : message from app %d : %s\n",nbytes, buffer );
if ( nbytes == -1) {
handle_error("file_read");
@ -665,7 +665,7 @@ void main_loop (struct service *srv) {
tab_req[nbclient].p = malloc(sizeof(struct process));
// -1 : error, 0 = no new process, 1 = new process
ret = server_get_new_request (buf, &tab_req[nbclient]);
ret = ipc_server_get_new_request (buf, &tab_req[nbclient]);
tab_req[nbclient].p->proc_fd = newfd;
if (ret == -1) {
perror("server_get_new_request()");
@ -716,7 +716,7 @@ void main_loop (struct service *srv) {
tab_req[nbclient].p = malloc(sizeof(struct process));
// -1 : error, 0 = no new process, 1 = new process
ret = server_get_new_request (buf, &tab_req[nbclient]);
ret = ipc_server_get_new_request (buf, &tab_req[nbclient]);
tab_req[nbclient].p->proc_fd = i;
if (ret == -1) {
perror("server_get_new_request()");
@ -775,12 +775,12 @@ void main_loop (struct service *srv) {
int main(int argc, char * argv[], char **env) {
struct service srv;
server_init (argc, argv, env, &srv, SERVICE_TCP, NULL);
ipc_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 = server_create (&srv))) {
if ((ret = ipc_server_create (&srv))) {
fprintf(stdout, "error service_create %d\n", ret);
exit (1);
}
@ -790,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 = server_close (&srv))) {
if ((ret = ipc_server_close (&srv))) {
fprintf(stdout, "error service_close %d\n", ret);
exit (1);
}

View File

@ -44,11 +44,11 @@ int fifo_create (char * path);
//create first message for a service : pid index version
void makePivMessage(char ** piv, int pid, int index, int version);
void * server_thread(void *reqq);
void * ipc_server_thread(void *reqq);
void * client_thread(void *reqq);
int server_get_new_request(char *buf, info_request *req);
int ipc_server_get_new_request(char *buf, info_request *req);
void request_print (const info_request *req);

View File

@ -38,7 +38,7 @@ int main(int argc, char * argv[]) {
exit(errno);
}
//printf("connected...\n");
file_write(sfd, server_message, strlen(server_message));
file_write(sfd, ipc_server_message, strlen(server_message));
//printf("%s\n", proc_message);
//sleep(1);
file_write(sfd, proc_message, strlen(proc_message));