some modifications and pingpong is now working with new version
This commit is contained in:
commit
7f0e5b62dd
@ -17,16 +17,22 @@ int file_write (const char *path, const char *buf, size_t msize)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int file_read (const char *path, char **buf, size_t *msize)
|
int file_read (const char *path, char **buf, size_t *msize)
|
||||||
{
|
{
|
||||||
|
if (buf == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
int fd = open (path, O_RDONLY);
|
int fd = open (path, O_RDONLY);
|
||||||
if (fd <= 0) {
|
if (fd <= 0) {
|
||||||
return ER_FILE_OPEN;
|
return ER_FILE_OPEN;
|
||||||
}
|
}
|
||||||
if (*buf == NULL)
|
printf("FILE_READ: opened file %s\n", path);
|
||||||
|
|
||||||
|
if (*buf == NULL) {
|
||||||
*buf = malloc (BUFSIZ);
|
*buf = malloc (BUFSIZ);
|
||||||
|
memset (*buf, 0, BUFSIZ);
|
||||||
|
}
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int ret2 = 0;
|
int ret2 = 0;
|
||||||
ret = read (fd, *buf, BUFSIZ);
|
ret = read (fd, *buf, BUFSIZ);
|
||||||
@ -36,12 +42,14 @@ int file_read (const char *path, char **buf, size_t *msize)
|
|||||||
else {
|
else {
|
||||||
*msize = ret;
|
*msize = ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret2 = close (fd);
|
ret2 = close (fd);
|
||||||
if (ret2 < 0) {
|
if (ret2 < 0) {
|
||||||
fprintf (stderr, "err: close [err: %d] %s\n", ret2, path);
|
fprintf (stderr, "err: close [err: %d] %s\n", ret2, path);
|
||||||
perror ("closing");
|
perror ("closing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +169,6 @@ int srv_get_new_process (const struct service *srv, struct process *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (buf != NULL)
|
if (buf != NULL)
|
||||||
free (buf);
|
free (buf);
|
||||||
srv_process_gen (p, pid, index, version);
|
srv_process_gen (p, pid, index, version);
|
||||||
|
@ -29,17 +29,6 @@ void srv_process_gen (struct process *p
|
|||||||
|
|
||||||
snprintf(p->path_in , PATH_MAX, "%s%d-%d-in" , TMPDIR, pid, index);
|
snprintf(p->path_in , PATH_MAX, "%s%d-%d-in" , TMPDIR, pid, index);
|
||||||
snprintf(p->path_out, PATH_MAX, "%s%d-%d-out", TMPDIR, pid, index);
|
snprintf(p->path_out, PATH_MAX, "%s%d-%d-out", TMPDIR, pid, index);
|
||||||
//printf("path-in : %s\n", p->path_in );
|
|
||||||
//printf("path-out : %s\n", p->path_out );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void srv_process_free (struct process * p)
|
|
||||||
{
|
|
||||||
// TODO nothing to do now
|
|
||||||
|
|
||||||
// snprintf(p->path_in , PATH_MAX, "%s/%d-%d-in" , TMPDIR, pid, index);
|
|
||||||
// snprintf(p->path_out, PATH_MAX, "%s/%d-%d-out", TMPDIR, pid, index);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +78,10 @@ int pubsubd_channel_new (struct channel *c, const char * name)
|
|||||||
|
|
||||||
printf ("NAME : %s, SIZE : %ld\n", name, nlen);
|
printf ("NAME : %s, SIZE : %ld\n", name, nlen);
|
||||||
|
|
||||||
if (c->chan == NULL)
|
if (c->chan == NULL) {
|
||||||
c->chan = malloc (nlen +1);
|
c->chan = malloc (nlen +1);
|
||||||
|
memset (c->chan, 0, nlen +1);
|
||||||
|
}
|
||||||
|
|
||||||
memset (c->chan, 0, nlen +1);
|
memset (c->chan, 0, nlen +1);
|
||||||
memcpy (c->chan, name, nlen);
|
memcpy (c->chan, name, nlen);
|
||||||
@ -126,8 +128,10 @@ void pubsubd_subscriber_init (struct app_list_head **chans) {
|
|||||||
if (chans == NULL)
|
if (chans == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (*chans == NULL)
|
if (*chans == NULL) {
|
||||||
*chans = malloc (sizeof(struct channels));
|
*chans = malloc (sizeof(struct channels));
|
||||||
|
memset (*chans, 0, sizeof(struct channels));
|
||||||
|
}
|
||||||
LIST_INIT(*chans);
|
LIST_INIT(*chans);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,12 +153,7 @@ void pubsubd_channel_print (const struct channel *c)
|
|||||||
if (c == NULL || c->chan == NULL)
|
if (c == NULL || c->chan == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (c->chan == NULL) {
|
|
||||||
printf ( "\033[32mchan name not available\033[00m\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf ( "\033[32mchan %s\033[00m\n", c->chan);
|
printf ( "\033[32mchan %s\033[00m\n", c->chan);
|
||||||
}
|
|
||||||
|
|
||||||
if (c->alh == NULL)
|
if (c->alh == NULL)
|
||||||
return;
|
return;
|
||||||
@ -173,6 +172,7 @@ struct app_list_elm * pubsubd_app_list_elm_copy (const struct app_list_elm *ale)
|
|||||||
|
|
||||||
struct app_list_elm * n = NULL;
|
struct app_list_elm * n = NULL;
|
||||||
n = malloc (sizeof (struct app_list_elm));
|
n = malloc (sizeof (struct app_list_elm));
|
||||||
|
memset (n, 0, sizeof (struct app_list_elm));
|
||||||
|
|
||||||
if (ale->p != NULL)
|
if (ale->p != NULL)
|
||||||
n->p = srv_process_copy (ale->p);
|
n->p = srv_process_copy (ale->p);
|
||||||
@ -248,6 +248,9 @@ void pubsubd_app_list_elm_create (struct app_list_elm *ale, struct process *p)
|
|||||||
if (ale == NULL)
|
if (ale == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (ale->p != NULL)
|
||||||
|
free (ale->p);
|
||||||
|
|
||||||
ale->p = srv_process_copy (p);
|
ale->p = srv_process_copy (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,6 +276,7 @@ void pubsubd_msg_serialize (const struct pubsub_msg *msg, char **data, size_t *l
|
|||||||
*data = NULL;
|
*data = NULL;
|
||||||
}
|
}
|
||||||
*data = malloc(*len);
|
*data = malloc(*len);
|
||||||
|
memset (*data, 0, *len);
|
||||||
data[0][0] = msg->type;
|
data[0][0] = msg->type;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -286,6 +290,7 @@ void pubsubd_msg_serialize (const struct pubsub_msg *msg, char **data, size_t *l
|
|||||||
*data = NULL;
|
*data = NULL;
|
||||||
}
|
}
|
||||||
*data = malloc(*len);
|
*data = malloc(*len);
|
||||||
|
memset (*data, 0, *len);
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
@ -334,6 +339,7 @@ void pubsubd_msg_unserialize (struct pubsub_msg *msg, const char *data, size_t l
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msg->chan = malloc (msg->chanlen);
|
msg->chan = malloc (msg->chanlen);
|
||||||
|
memset (msg->chan, 0, msg->chanlen);
|
||||||
memcpy (msg->chan, data + i, msg->chanlen); i += msg->chanlen;
|
memcpy (msg->chan, data + i, msg->chanlen); i += msg->chanlen;
|
||||||
|
|
||||||
memcpy (&msg->datalen, data + i, sizeof(size_t)); i += sizeof(size_t);
|
memcpy (&msg->datalen, data + i, sizeof(size_t)); i += sizeof(size_t);
|
||||||
@ -342,6 +348,7 @@ void pubsubd_msg_unserialize (struct pubsub_msg *msg, const char *data, size_t l
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msg->data = malloc (msg->datalen);
|
msg->data = malloc (msg->datalen);
|
||||||
|
memset (msg->data, 0, msg->datalen);
|
||||||
memcpy (msg->data, data + i, msg->datalen); i += msg->datalen;
|
memcpy (msg->data, data + i, msg->datalen); i += msg->datalen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,9 +396,15 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
|||||||
char chan[BUFSIZ];
|
char chan[BUFSIZ];
|
||||||
memset (chan, 0, BUFSIZ);
|
memset (chan, 0, BUFSIZ);
|
||||||
|
|
||||||
|
if (buf == NULL) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
printf ("INIT: %s\n", buf);
|
printf ("INIT: %s\n", buf);
|
||||||
|
|
||||||
for (str = buf, i = 1; ; str = NULL, i++) {
|
for (str = buf, i = 1; ; str = NULL, i++) {
|
||||||
|
if (str == NULL)
|
||||||
|
break;
|
||||||
token = strtok_r(str, " ", &saveptr);
|
token = strtok_r(str, " ", &saveptr);
|
||||||
if (token == NULL)
|
if (token == NULL)
|
||||||
break;
|
break;
|
||||||
@ -441,17 +454,19 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
|||||||
}
|
}
|
||||||
|
|
||||||
ale->p = malloc (sizeof (struct process));
|
ale->p = malloc (sizeof (struct process));
|
||||||
|
memset (ale->p, 0, sizeof (struct process));
|
||||||
srv_process_gen (ale->p, pid, index, version);
|
srv_process_gen (ale->p, pid, index, version);
|
||||||
|
|
||||||
if (*c == NULL) {
|
if (*c == NULL) {
|
||||||
*c = malloc (sizeof (struct channel));
|
*c = malloc (sizeof (struct channel));
|
||||||
|
memset (*c, 0, sizeof (struct channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
chan[BUFSIZ -1] = '\0';
|
chan[BUFSIZ -1] = '\0';
|
||||||
pubsubd_channel_new (*c, chan);
|
pubsubd_channel_new (*c, chan);
|
||||||
|
|
||||||
|
|
||||||
struct channel *new_chan = NULL;
|
struct channel *new_chan = NULL;
|
||||||
|
|
||||||
new_chan = pubsubd_channel_get (chans, *c);
|
new_chan = pubsubd_channel_get (chans, *c);
|
||||||
if (new_chan == NULL) {
|
if (new_chan == NULL) {
|
||||||
new_chan = pubsubd_channels_add (chans, *c);
|
new_chan = pubsubd_channels_add (chans, *c);
|
||||||
|
Binary file not shown.
@ -77,6 +77,7 @@ int main(int argc, char * argv[], char **env)
|
|||||||
fprintf(stdout, "error service_create %d\n", ret);
|
fprintf(stdout, "error service_create %d\n", ret);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
printf("MAIN: server created\n" );
|
||||||
|
|
||||||
// the service will loop until the end of time, a specific message, a signal
|
// the service will loop until the end of time, a specific message, a signal
|
||||||
main_loop (&srv);
|
main_loop (&srv);
|
||||||
|
@ -2,15 +2,13 @@
|
|||||||
|
|
||||||
REP=/tmp/ipc/
|
REP=/tmp/ipc/
|
||||||
SERVICE="pongd"
|
SERVICE="pongd"
|
||||||
NB=3
|
NB=10
|
||||||
|
|
||||||
# CLEAN UP !
|
# CLEAN UP !
|
||||||
if [ $# -ne 0 ] && [ "$1" = clean ]
|
if [ $# -ne 0 ] && [ "$1" = clean ]
|
||||||
then
|
then
|
||||||
echo "clean rep ${REP}"
|
echo "clean rep ${REP}"
|
||||||
rm ${REP}/${SERVICE}
|
rm ${REP}/${SERVICE}
|
||||||
rm ${REP}/*-in
|
|
||||||
rm ${REP}/*-out
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@ -22,8 +20,6 @@ fi
|
|||||||
|
|
||||||
for pid in `seq 1 ${NB}`
|
for pid in `seq 1 ${NB}`
|
||||||
do
|
do
|
||||||
echo "${pid}"
|
|
||||||
|
|
||||||
# we make the application pipes
|
# we make the application pipes
|
||||||
mkfifo ${REP}${pid}-1-in 2>/dev/null
|
mkfifo ${REP}${pid}-1-in 2>/dev/null
|
||||||
mkfifo ${REP}${pid}-1-out 2>/dev/null
|
mkfifo ${REP}${pid}-1-out 2>/dev/null
|
||||||
@ -36,5 +32,10 @@ do
|
|||||||
# echo "hello world" > ${REP}${pid}-1-out
|
# echo "hello world" > ${REP}${pid}-1-out
|
||||||
|
|
||||||
# the the service will answer with our message
|
# the the service will answer with our message
|
||||||
|
echo "pid : ${pid}"
|
||||||
cat ${REP}/${pid}-1-in
|
cat ${REP}/${pid}-1-in
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "clean rep"
|
||||||
|
rm ${REP}/*-in
|
||||||
|
rm ${REP}/*-out
|
@ -27,7 +27,7 @@ main(int argc, char **argv)
|
|||||||
struct channels chans;
|
struct channels chans;
|
||||||
memset (&chans, 0, sizeof (struct channels));
|
memset (&chans, 0, sizeof (struct channels));
|
||||||
|
|
||||||
for (int nb = 10, i = 0 ; nb > 0; i++, nb--) {
|
for (int nb = 1, i = 0 ; nb > 0; i++, nb--) {
|
||||||
struct app_list_elm ale;
|
struct app_list_elm ale;
|
||||||
memset (&ale, 0, sizeof (struct app_list_elm));
|
memset (&ale, 0, sizeof (struct app_list_elm));
|
||||||
|
|
||||||
@ -42,6 +42,8 @@ main(int argc, char **argv)
|
|||||||
pubsubd_channels_print (&chans);
|
pubsubd_channels_print (&chans);
|
||||||
printf ("--\n");
|
printf ("--\n");
|
||||||
printf ("still %d remaining processes\n", nb);
|
printf ("still %d remaining processes\n", nb);
|
||||||
|
|
||||||
|
pubsubd_app_list_elm_free (&ale);
|
||||||
}
|
}
|
||||||
|
|
||||||
pubsubd_channels_del_all (&chans);
|
pubsubd_channels_del_all (&chans);
|
||||||
|
Reference in New Issue
Block a user