irctk

libircclient binding for scripts
git clone https://a3nm.net/git/irctk/
Log | Files | Refs | README

commit 54faec25410362bf59a7cf2075f55ebbb91f8920
parent ffa34f84924c7820c56f156c12e7b8087b913f3c
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sun,  1 Jul 2012 11:47:33 +0200

fix bugs

Diffstat:
TODO | 4++++
irctk.c | 70+++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 59 insertions(+), 15 deletions(-)

diff --git a/TODO b/TODO @@ -1,3 +1,7 @@ +debug: seq 3 | valgrind --leak-check=full ./irctk -y 999 -i 99 -l -Fvfr 127.0.0.1 \#test1 \#test2 \#test3 + +do we die on broken pipes? + handle nick following ssl support password support diff --git a/irctk.c b/irctk.c @@ -646,10 +646,11 @@ void push_one(fifo_set *s, char *fl, char *dest, char *l, int next_dep_fifoidx, int next_dep_lineidx, int *fifoidx, int *lineidx) { int c = index_of_chan(s, dest); - debug("PUSH_ONE \"%s\" (%p), nextdep %d %d ioc %d", l, l, next_dep_fifoidx, next_dep_lineidx, c); fifo *f = &(s->fifos[c]); if (s->was_pushed[c]) return; // already pushed + debug("PUSH_ONE \"%s\" (%p), nextdep %d %d ioc %d position %d", l, l, next_dep_fifoidx, next_dep_lineidx, c, + f->tl); s->was_pushed[c] = 1; f->queue[f->tl].line = l; f->queue[f->tl].full_line = fl; @@ -666,10 +667,10 @@ void push_one(fifo_set *s, char *fl, char *dest, char *l, void set_last_idxes(fifo_set *s, char *chan, int fifoidx, int lineidx) { int c = index_of_chan(s, chan); fifo *f = &(s->fifos[c]); - debug("set_last_ptr %d %d for \"%s\" ioc %d", fifoidx, lineidx, - f->queue[f->tl - 1 + LINE_BUFFER % LINE_BUFFER].full_line, c); - f->queue[f->tl - 1 + LINE_BUFFER % LINE_BUFFER].next_dep_fifoidx = fifoidx; - f->queue[f->tl - 1 + LINE_BUFFER % LINE_BUFFER].next_dep_lineidx = lineidx; + debug("set_last_ptr %d %d for \"%s\" ioc %d position %d", fifoidx, lineidx, + f->queue[(f->tl - 1 + LINE_BUFFER) % LINE_BUFFER].line, c, (f->tl - 1 + LINE_BUFFER) % LINE_BUFFER); + f->queue[(f->tl - 1 + LINE_BUFFER) % LINE_BUFFER].next_dep_fifoidx = fifoidx; + f->queue[(f->tl - 1 + LINE_BUFFER) % LINE_BUFFER].next_dep_lineidx = lineidx; } void reset_chan_marks(fifo_set *s) { @@ -678,14 +679,27 @@ void reset_chan_marks(fifo_set *s) { s->was_pushed[i] = 0; } -void push_fifo_set(fifo_set *s, char *fl, char *dests, char *l) { - debug("push_fifo_set full_line \"%s\" (%p) \"%s\" (%p)", fl, fl, l, l); - int was_empty; +void pre_push(fifo_set *s) { pthread_mutex_lock(&s->ctrl.mutex); while (full_fifo_set(s)) pthread_cond_wait(&s->ctrl.full, &s->ctrl.mutex); // now fifo_set isn't full +} + +void post_push(fifo_set *s, int was_empty) { + if (was_empty) { + debug("signal for empty"); + pthread_cond_signal(&s->ctrl.empty); + } + pthread_mutex_unlock(&s->ctrl.mutex); +} +void push_fifo_set(fifo_set *s, char *fl, char *dests, char *l) { + debug("push_fifo_set full_line \"%s\" (%p) line \"%s\" (%p) dests %s", + fl, fl, l, l, dests); + int was_empty; + + pre_push(s); int i = 0; int cont = 1; char *last_dest, *first_dest; @@ -727,13 +741,41 @@ void push_fifo_set(fifo_set *s, char *fl, char *dests, char *l) { // first_ptr->full_line, first_dest); set_last_idxes(s, first_dest, first_fifoidx, first_lineidx); - if (was_empty) { - debug("signal for empty"); - pthread_cond_signal(&s->ctrl.empty); + post_push(s, was_empty); +} + +void push_fifo_set_all(fifo_set *s, char *fl, char **dests, int ndests, char *l) { + pre_push(s); + int was_empty; + int i = 0; + int first_fifoidx = -1, first_lineidx = -1; + int fifoidx = 0, lineidx = 0, nfifoidx = 0, nlineidx = 0; + + assert(ndests > 0); + reset_chan_marks(s); + was_empty = empty_fifo_set(s); + for (i=0; i<ndests; i++) + { + push_one(s, i?NULL:fl, dests[i], l, fifoidx, lineidx, &nfifoidx, &nlineidx); + fifoidx = nfifoidx; + lineidx = nlineidx; + if (first_fifoidx < 0) { + first_fifoidx = fifoidx; + first_lineidx = lineidx; + // debug("first_ptr is %p full line %s, first_dest is %s", first_ptr, + // first_ptr->full_line, first_dest); + } } - pthread_mutex_unlock(&s->ctrl.mutex); + //debug("DDD %s", s->fifos[0].queue[0].line); + debug("finished at i:%d", i); + + // debug("first_ptr is %p full line %s, first_dest is %s", first_ptr, + // first_ptr->full_line, first_dest); + set_last_idxes(s, dests[0], first_fifoidx, first_lineidx); + post_push(s, was_empty); } + void mark_head(fifo *f) { f->queue[f->hd].is_head = 1; f->queue[f->hd].is_sendable = 0; @@ -938,7 +980,6 @@ int do_cmd_msg(irc_session_t *s, char* chan, char* line) // Handle a command request which might not specify a destination void cmd_msg(char *full_line, char *target, char *line) { - int i = 0; char *msg; debug("cmd_msg %s \"%s\" (%p), last_in %s", target, line, line, args.last_chan_in); @@ -980,8 +1021,7 @@ void cmd_msg(char *full_line, char *target, char *line) //TODO also for chans joined at runtime //TODO2: ugly, could have generated the comma-separated string //like for last_chans_out! - for (i = 0; i < args.n_channels; i++) - push_fifo_set(&fifos, i?NULL:full_line, args.channels[i], line); + push_fifo_set_all(&fifos, full_line, args.channels, args.n_channels, line); /* TODO return value */ default: