Obsolete
/
libipc-old
Archived
3
0
Fork 0

pubsubd: chan search, add, del => ok

more_to_read
Philippe PITTOLI 2016-09-11 02:18:12 +02:00
parent 615395b0f3
commit 57168fb1ef
3 changed files with 35 additions and 27 deletions

View File

@ -114,9 +114,14 @@ struct channel * pubsubd_channel_search (struct channels *chans, char *chan)
{
struct channel * np = NULL;
LIST_FOREACH(np, chans, entries) {
if (np->chanlen == strlen (chan) + 1
&& strncmp (np->chan, chan, np->chanlen))
// TODO debug
printf ("pubsubd_channel_search: %s (%ld) vs %s (%ld)\n"
, np->chan, np->chanlen, chan, strlen(chan));
if (np->chanlen == strlen (chan)
&& strncmp (np->chan, chan, np->chanlen) == 0) {
printf ("pubsubd_channel_search: FOUND\n");
return np;
}
}
return NULL;
}
@ -163,27 +168,19 @@ void pubsubd_channels_print (const struct channels *chans)
struct channel *chan = NULL;
LIST_FOREACH(chan, chans, entries) {
pubsubd_channel_print (chan);
if (chan->chan == NULL) {
printf ("pubsubd_channels_print: chan->chan == NULL\n");
}
printf ( "\033[32mchan %s\033[00m\n", chan->chan);
if (chan->alh == NULL)
printf ("pubsubd_channels_print: chan->alh == NULL\n");
else
pubsubd_subscriber_print (chan->alh);
}
}
void pubsubd_channel_print (const struct channel *c)
{
if (c == NULL || c->chan == NULL) {
printf ("pubsubd_channel_print: c == NULL or c->chan == NULL\n");
return;
}
printf ( "\033[32mchan %s\033[00m\n", c->chan);
if (c->alh == NULL) {
printf ("pubsubd_channel_print: c->alh == NULL\n");
return;
}
pubsubd_subscriber_print (c->alh);
}
struct app_list_elm * pubsubd_app_list_elm_copy (const struct app_list_elm *ale)
{
if (ale == NULL)

View File

@ -3,6 +3,9 @@
#define TEST_NAME "test-chan-lists"
#define CHAN1 "coucou"
#define CHAN2 "salut"
void
ohshit(int rvalue, const char* str) {
fprintf(stderr, "%s\n", str);
@ -33,9 +36,9 @@ main(int argc, char **argv, char **env)
// FIRST CHAN TO BE ADDED
// search for the chan in channels, add it if not found
struct channel *new_chan = NULL;
new_chan = pubsubd_channel_search (&chans, "coucou");
new_chan = pubsubd_channel_search (&chans, CHAN1);
if (new_chan == NULL) {
new_chan = pubsubd_channels_add (&chans, "coucou");
new_chan = pubsubd_channels_add (&chans, CHAN1);
pubsubd_subscriber_init (&new_chan->alh);
}
else {
@ -49,7 +52,7 @@ main(int argc, char **argv, char **env)
// SAME CHAN, SHOULD NOT BE ADDED
// search for the chan in channels, add it if not found
new_chan = pubsubd_channel_search (&chans, "coucou");
new_chan = pubsubd_channel_search (&chans, CHAN1);
if (new_chan == NULL) {
ohshit (3, "error : same chan, shouldn't be added in channels");
}
@ -64,9 +67,9 @@ main(int argc, char **argv, char **env)
// NEW CHAN, SHOULD BE ADDED
// search for the chan in channels, add it if not found
new_chan = pubsubd_channel_search (&chans, "salut");
new_chan = pubsubd_channel_search (&chans, CHAN2);
if (new_chan == NULL) {
new_chan = pubsubd_channels_add (&chans, "salut");
new_chan = pubsubd_channels_add (&chans, CHAN2);
pubsubd_subscriber_init (&new_chan->alh);
}
else {

View File

@ -1,7 +1,15 @@
#!/bin/bash
for i in $(seq 1 10)
REP=/tmp/ipc
SERVICE=gen
#SERVICE=pubsub
NB=10
for i in $(seq 1 ${NB})
do
echo "${i} 1 1 sub chan1" > /tmp/ipc/gen
mkfifo ${REP}/${i}-1-1-in
mkfifo ${REP}/${i}-1-1-out
echo "${i} 1 1 both chan1" > ${REP}/${SERVICE}
sleep 0.1
done